class Falcon::Hosts
def add(name, host = Host.new, &block)
def add(name, host = Host.new, &block) host = Host.new yield host if block_given? @named[name] = host.freeze end
def client_endpoints
def client_endpoints Hash[ @named.collect{|name, host| [name, host.endpoint]} ] end
def each(&block)
def each(&block) @named.each(&block) end
def endpoint
def endpoint @server_endpoint ||= Async::HTTP::URLEndpoint.parse( 'https://[::]', ssl_context: self.ssl_context, reuse_address: true ) end
def host_context(socket, hostname)
def host_context(socket, hostname) if host = @named[hostname] socket.hostname = hostname return host.ssl_context end end
def initialize
def initialize @named = {} @server_context = nil @server_endpoint = nil end
def proxy
def proxy Proxy.new(Falcon::BadRequest, self.client_endpoints) end
def ssl_context
def ssl_context @server_context ||= OpenSSL::SSL::SSLContext.new.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.setup end end