httpd()
public
Run WEBrick HTTP server.
ruby -run -e httpd -- [OPTION] DocumentRoot
--bind-address=ADDR address to bind
--port=NUM listening port number
--max-clients=MAX max number of simultaneous clients
--temp-dir=DIR temporary directory
--do-not-reverse-lookup disable reverse lookup
--request-timeout=SECOND request timeout in seconds
--http-version=VERSION HTTP version
-v verbose
# File lib/un.rb, line 313
def httpd
setup("", "BindAddress=ADDR", "Port=PORT", "MaxClients=NUM", "TempDir=DIR",
"DoNotReverseLookup", "RequestTimeout=SECOND", "HTTPVersion=VERSION") do
|argv, options|
require 'webrick'
opt = options[:RequestTimeout] and options[:RequestTimeout] = opt.to_i
[:Port, :MaxClients].each do |name|
opt = options[name] and (options[name] = Integer(opt)) rescue nil
end
unless argv.size == 1
raise ArgumentError, "DocumentRoot is mandatory"
end
options[:DocumentRoot] = argv.shift
s = WEBrick::HTTPServer.new(options)
shut = proc {s.shutdown}
siglist = %TERM QUIT"
siglist.concat(%HUP INT") if STDIN.tty?
siglist &= Signal.list.keys
siglist.each do |sig|
Signal.trap(sig, shut)
end
s.start
end
end