Class: Async::HTTP::Protocol::HTTPS

Inherits:
Object
  • Object
show all
Defined in:
lib/async/http/protocol/https.rb

Overview

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

Constant Summary collapse

HANDLERS =

The protocol classes for each supported protocol.

{
	"h2" => HTTP2,
	"http/1.1" => HTTP11,
	"http/1.0" => HTTP10,
	nil => HTTP11,
}

Instance Method Summary collapse

Constructor Details

#initialize(handlers = HANDLERS, **options) ⇒ HTTPS

Returns a new instance of HTTPS.



26
27
28
29
# File 'lib/async/http/protocol/https.rb', line 26

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

Instance Method Details

#add(name, protocol, **options) ⇒ Object



31
32
33
34
# File 'lib/async/http/protocol/https.rb', line 31

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

#client(peer, **options) ⇒ Object

Create a client for an outbound connection.



59
60
61
62
63
64
# File 'lib/async/http/protocol/https.rb', line 59

def client(peer, **options)
	protocol = protocol_for(peer)
	options = options[protocol] || {}
	
	protocol.client(peer, **options)
end

#namesObject



78
79
80
# File 'lib/async/http/protocol/https.rb', line 78

def names
	@handlers.keys.compact
end

#protocol_for(peer) ⇒ Object

Determine the protocol of the peer and return the appropriate protocol class.

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



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/async/http/protocol/https.rb', line 42

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

#server(peer, **options) ⇒ Object

Create a server for an inbound connection.



70
71
72
73
74
75
# File 'lib/async/http/protocol/https.rb', line 70

def server(peer, **options)
	protocol = protocol_for(peer)
	options = options[protocol] || {}
	
	protocol.server(peer, **options)
end