/
https.rb
52 lines (42 loc) · 1.16 KB
/
https.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# frozen_string_literal: true
# Released under the MIT License.
# Copyright, 2018-2024, by Samuel Williams.
# Copyright, 2019, by Brian Morearty.
require_relative 'http10'
require_relative 'http11'
require_relative 'http2'
module Async
module HTTP
module Protocol
# A server that supports both HTTP1.0 and HTTP1.1 semantics by detecting the version of the request.
module HTTPS
HANDLERS = {
"h2" => HTTP2,
"http/1.1" => HTTP11,
"http/1.0" => HTTP10,
nil => HTTP11,
}
def self.protocol_for(peer)
# alpn_protocol is only available if openssl v1.0.2+
name = peer.alpn_protocol
Console.logger.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 self.client(peer)
protocol_for(peer).client(peer)
end
def self.server(peer)
protocol_for(peer).server(peer)
end
# Supported Application Layer Protocol Negotiation names:
def self.names
HANDLERS.keys.compact
end
end
end
end
end