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
Register a protocol handler for a given ALPN protocol name.
-
#client(peer, **options) ⇒ Object
Create a client for an outbound connection.
-
#initialize(handlers = HANDLERS, **options) ⇒ HTTPS
constructor
Initialize the HTTPS protocol negotiator.
- #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
Register a protocol handler for a given ALPN protocol name.
38 39 40 41 |
# File 'lib/async/http/protocol/https.rb', line 38 def add(name, protocol, **) @handlers[name] = protocol @options[protocol] = end |
#client(peer, **options) ⇒ Object
Create a client for an outbound connection.
66 67 68 69 70 71 |
# File 'lib/async/http/protocol/https.rb', line 66 def client(peer, **) protocol = protocol_for(peer) = [protocol] || {} protocol.client(peer, **) end |
#names ⇒ Object
85 86 87 |
# File 'lib/async/http/protocol/https.rb', line 85 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.
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/async/http/protocol/https.rb', line 49 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.
77 78 79 80 81 82 |
# File 'lib/async/http/protocol/https.rb', line 77 def server(peer, **) protocol = protocol_for(peer) = [protocol] || {} protocol.server(peer, **) end |