diff options
Diffstat (limited to 'lib/webrick/https.rb')
| -rw-r--r-- | lib/webrick/https.rb | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/lib/webrick/https.rb b/lib/webrick/https.rb index 73875d7326..b0a49bc40b 100644 --- a/lib/webrick/https.rb +++ b/lib/webrick/https.rb @@ -9,7 +9,8 @@ # # $IPR: https.rb,v 1.15 2003/07/22 19:20:42 gotoyuzo Exp $ -require 'webrick/ssl' +require_relative 'ssl' +require_relative 'httpserver' module WEBrick module Config @@ -84,4 +85,68 @@ module WEBrick # :startdoc: end + + ## + #-- + # Fake WEBrick::HTTPRequest for lookup_server + + class SNIRequest + + ## + # The SNI hostname + + attr_reader :host + + ## + # The socket address of the server + + attr_reader :addr + + ## + # The port this request is for + + attr_reader :port + + ## + # Creates a new SNIRequest. + + def initialize(sslsocket, hostname) + @host = hostname + @addr = sslsocket.addr + @port = @addr[1] + end + end + + + ## + #-- + # Adds SSL functionality to WEBrick::HTTPServer + + class HTTPServer < ::WEBrick::GenericServer + ## + # ServerNameIndication callback + + def ssl_servername_callback(sslsocket, hostname = nil) + req = SNIRequest.new(sslsocket, hostname) + server = lookup_server(req) + server ? server.ssl_context : nil + end + + # :stopdoc: + + ## + # Check whether +server+ is also SSL server. + # Also +server+'s SSL context will be created. + + alias orig_virtual_host virtual_host + + def virtual_host(server) + if @config[:SSLEnable] && !server.ssl_context + raise ArgumentError, "virtual host must set SSLEnable to true" + end + orig_virtual_host(server) + end + + # :startdoc: + end end |
