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
--ssl-certificate=CERT The SSL certificate file for the server
--ssl-private-key=KEY The SSL private key file for the server certificate
-v verbose
# File lib/un.rb, line 321
def httpd
setup("", "BindAddress=ADDR", "Port=PORT", "MaxClients=NUM", "TempDir=DIR",
"DoNotReverseLookup", "RequestTimeout=SECOND", "HTTPVersion=VERSION",
"SSLCertificate=CERT", "SSLPrivateKey=KEY") 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
if cert = options[:SSLCertificate]
key = options[:SSLPrivateKey] or
raise "--ssl-private-key option must also be given"
require 'webrick/https'
options[:SSLEnable] = true
options[:SSLCertificate] = OpenSSL::X509::Certificate.new(File.read(cert))
options[:SSLPrivateKey] = OpenSSL::PKey.read(File.read(key))
options[:Port] ||= 8443 # HTTPS Alternate
end
options[:Port] ||= 8080 # HTTP Alternate
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