lib/falcon/hosts.rb in falcon-0.14.1 vs lib/falcon/hosts.rb in falcon-0.14.2

- old
+ new

@@ -25,35 +25,48 @@ def initialize @app = nil @endpoint = nil @ssl_certificate = nil @ssl_key = nil + + @ssl_context = nil end attr_accessor :app attr_accessor :endpoint attr_accessor :ssl_certificate attr_accessor :ssl_key + attr_accessor :ssl_context + def freeze + return if frozen? + + ssl_context + + super + end + def ssl_certificate_path= path @ssl_certificate = OpenSSL::X509::Certificate.new(File.read(path)) end def ssl_key_path= path @ssl_key = OpenSSL::PKey::RSA.new(File.read(path)) end def ssl_context - if @ssl_key - OpenSSL::SSL::SSLContext.new.tap do |context| - context.cert = @ssl_certificate - context.key = @ssl_key - - context.set_params - end + @ssl_context ||= OpenSSL::SSL::SSLContext.new(:TLSv1).tap do |context| + context.cert = @ssl_certificate + context.key = @ssl_key + + context.session_id_context = "falcon" + + context.set_params + + context.freeze end end def start if app = self.app @@ -79,24 +92,28 @@ @named.each(&block) end def endpoint @server_endpoint ||= Async::HTTP::URLEndpoint.parse( - 'https://0.0.0.0', + 'https://[::]', ssl_context: self.ssl_context, reuse_address: true ) end def ssl_context - @server_context ||= OpenSSL::SSL::SSLContext.new.tap do |context| + @server_context ||= OpenSSL::SSL::SSLContext.new(:TLSv1).tap do |context| context.servername_cb = Proc.new do |socket, hostname| self.host_context(socket, hostname) end + context.session_id_context = "falcon" + context.alpn_protocols = DEFAULT_ALPN_PROTOCOLS context.set_params + + context.freeze end end def host_context(socket, hostname) if host = @named[hostname]