Class: Async::HTTP::Protocol::HTTPS
- Inherits:
-
Object
- Object
- Async::HTTP::Protocol::HTTPS
- 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
- #add(name, protocol, **options) ⇒ Object
-
#client(peer, **options) ⇒ Object
Create a client for an outbound connection.
-
#initialize(handlers = HANDLERS, **options) ⇒ HTTPS
constructor
A new instance of HTTPS.
- #names ⇒ Object
-
#protocol_for(peer) ⇒ Object
Determine the protocol of the peer and return the appropriate protocol class.
-
#server(peer, **options) ⇒ Object
Create a server for an inbound connection.
Constructor Details
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, **) @handlers[name] = protocol @options[protocol] = 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, **) protocol = protocol_for(peer) = [protocol] || {} protocol.client(peer, **) end |
#names ⇒ Object
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, **) protocol = protocol_for(peer) = [protocol] || {} protocol.server(peer, **) end |