class Async::HTTP::Protocol::HTTPS

A server that supports both HTTP1.0 and HTTP1.1 semantics by detecting the version of the request.

def add(name, protocol, **options)

def add(name, protocol, **options)
	@handlers[name] = protocol
	@options[protocol] = options
end

def client(peer, **options)

@parameter options [Hash] Options to pass to the client instance.
@parameter peer [IO] The peer to communicate with.

Create a client for an outbound connection.
def client(peer, **options)
	protocol = protocol_for(peer)
	options = options[protocol] || {}
	
	protocol.client(peer, **options)
end

def initialize(handlers = HANDLERS, **options)

def initialize(handlers = HANDLERS, **options)
	@handlers = handlers
	@options = options
end

def names

@returns [Array] The names of the supported protocol, used for Application Layer Protocol Negotiation (ALPN).
def names
	@handlers.keys.compact
end

def protocol_for(peer)

@returns [Class] The protocol class to use.
@parameter peer [IO] The peer to communicate with.

Use TLS Application Layer Protocol Negotiation (ALPN) to determine the protocol.

Determine the protocol of the peer and return the appropriate protocol class.
def protocol_for(peer)
	# alpn_protocol is only available if openssl v1.0.2+
	name = peer.alpn_protocol
	
	Console.debug(self) {"Negotiating protocol #{name.inspect}..."}
	
	if protocol = HANDLERS[name]
		return protocol
	else
		raise ArgumentError, "Could not determine protocol for connection (#{name.inspect})."
	end
end

def server(peer, **options)

@parameter options [Hash] Options to pass to the server instance.
@parameter peer [IO] The peer to communicate with.

Create a server for an inbound connection.
def server(peer, **options)
	protocol = protocol_for(peer)
	options = options[protocol] || {}
	
	protocol.server(peer, **options)
end