Project

General

Profile

Feature #13714 ยป add-https-support-to-httpd-function.rb

Patch implementing the feature - against trunk - flavio (Flavio Castelli), 07/04/2017 04:08 PM

 
diff --git a/lib/un.rb b/lib/un.rb
index b644fd9be4..b0bd875a8a 100644
--- a/lib/un.rb
+++ b/lib/un.rb
@@ -318,7 +318,8 @@ def mkmf
def httpd
setup("", "BindAddress=ADDR", "Port=PORT", "MaxClients=NUM", "TempDir=DIR",
- "DoNotReverseLookup", "RequestTimeout=SECOND", "HTTPVersion=VERSION") do
+ "DoNotReverseLookup", "RequestTimeout=SECOND", "HTTPVersion=VERSION",
+ "SSLCertificate=CERT", "SSLPrivateKey=KEY") do
|argv, options|
require 'webrick'
opt = options[:RequestTimeout] and options[:RequestTimeout] = opt.to_i
@@ -327,6 +328,15 @@ def httpd
end
options[:Port] ||= 8080 # HTTP Alternate
options[:DocumentRoot] = argv.shift || '.'
+ if options[:SSLCertificate]
+ require 'webrick/https'
+ require 'openssl'
+ options[:SSLCertificate] = OpenSSL::X509::Certificate.new(File.read(options[:SSLCertificate]))
+ options[:SSLEnable] = true
+ if options[:SSLPrivateKey]
+ options[:SSLPrivateKey] = OpenSSL::PKey::RSA.new(File.read(options[:SSLPrivateKey]))
+ end
+ end
s = WEBrick::HTTPServer.new(options)
shut = proc {s.shutdown}
siglist = %w"TERM QUIT"
    (1-1/1)