async-http 0.45.9 → 0.46.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db1594d1f164cc3ab8f63d2c4b4b9b75fa1ca13f564ea4a4908b6fa27aabf0b9
4
- data.tar.gz: 6df7e3e2c1a82dcdd699ec612bf7d9e7ad293baaba308f7a61935af5966ea7c9
3
+ metadata.gz: 354c7fb881a4d777bdf8f19a4c333b832e3bbc81f4dfa7e9851c3aa983d9bc7b
4
+ data.tar.gz: 9408b0a577c8162b2479e485e1d098d271717c8f9043a9c1bfa931655b650821
5
5
  SHA512:
6
- metadata.gz: a59e18445d9e8d31bb08a577d46d88dec3a758a481f57577a22612dbe435f6ff89ff22ac1a4cff15b56f59774ccdad8ebde939186ecd411102ac03ac944334ea
7
- data.tar.gz: 9577d519fd0d5d7207df86243e9ce11842b32113d8ac7a21744d7a4089ee16ffed5aa99fbe8f8e772ea99b3bb81dc4c8569db73ad3c1fcf0aeca72c146fd1a3e
6
+ metadata.gz: 709eb4507c6d562ae0eb69594ccb7f77d88d48be7259ac3ed215bb84a4c6e3de252fe9aff141cbbc1bd98e522b2d36442b4ce9dfab715b64a7ded784b00224a1
7
+ data.tar.gz: 9d45db2e2e87d3c89da79518ea7c0685b005c8b07ea295b7501a5ec6f093786c35ec6fe7b858d66c0ce57397ab295488694711681a7e7c4b4109ad4a38d6b76a
@@ -34,6 +34,10 @@ module Async
34
34
  # * If there are already connections, it will reuse it.
35
35
  # * If a request fails, it will retry it up to N times if it was idempotent.
36
36
  # The client object will never become unusable. It internally manages persistent connections (or non-persistent connections if that's required).
37
+ # @param endpoint [Endpoint] the endpoint to connnect to.
38
+ # @param protocol [Protocol::HTTP1 | Protocol::HTTP2 | Protocol::HTTPS] the protocol to use.
39
+ # @param scheme [String] The default scheme to set to requests.
40
+ # @param authority [String] The default authority to set to requests.
37
41
  def initialize(endpoint, protocol = endpoint.protocol, scheme = endpoint.scheme, authority = endpoint.authority, retries: 3, connection_limit: nil)
38
42
  @endpoint = endpoint
39
43
  @protocol = protocol
@@ -27,11 +27,12 @@ require_relative 'protocol/https'
27
27
 
28
28
  module Async
29
29
  module HTTP
30
+ # Represents a way to connect to a remote HTTP server.
30
31
  class Endpoint < Async::IO::Endpoint
31
32
  def self.parse(string, **options)
32
33
  url = URI.parse(string).normalize
33
34
 
34
- self.new(url, **options)
35
+ return self.new(url, nil, **options)
35
36
  end
36
37
 
37
38
  # @option scheme [String] the scheme to use, overrides the URL scheme.
@@ -67,7 +68,6 @@ module Async
67
68
  end
68
69
 
69
70
  attr :url
70
- attr :options
71
71
 
72
72
  def address
73
73
  endpoint.address
@@ -78,10 +78,12 @@ module Async
78
78
  end
79
79
 
80
80
  def protocol
81
- if secure?
82
- Protocol::HTTPS
83
- else
84
- Protocol::HTTP1
81
+ @options.fetch(:protocol) do
82
+ if secure?
83
+ Protocol::HTTPS
84
+ else
85
+ Protocol::HTTP1
86
+ end
85
87
  end
86
88
  end
87
89
 
@@ -124,18 +126,17 @@ module Async
124
126
  return buffer
125
127
  end
126
128
 
127
- DEFAULT_ALPN_PROTOCOLS = ['h2', 'http/1.1'].freeze
128
-
129
129
  def alpn_protocols
130
- @options[:alpn_protocols] || DEFAULT_ALPN_PROTOCOLS
130
+ @options.fetch(:alpn_protocols) {self.protocol.names}
131
131
  end
132
132
 
133
- LOCALHOST = 'localhost'.freeze
133
+ def localhost?
134
+ self.hostname =~ /^(.*?\.)?localhost\.?$/
135
+ end
134
136
 
135
137
  # We don't try to validate peer certificates when talking to localhost because they would always be self-signed.
136
138
  def ssl_verify_mode
137
- case self.hostname
138
- when LOCALHOST
139
+ if self.localhost?
139
140
  OpenSSL::SSL::VERIFY_NONE
140
141
  else
141
142
  OpenSSL::SSL::VERIFY_PEER
@@ -162,6 +163,7 @@ module Async
162
163
  options.delete(:hostname)
163
164
  options.delete(:ssl_context)
164
165
  options.delete(:alpn_protocols)
166
+ options.delete(:protocol)
165
167
 
166
168
  return options
167
169
  end
@@ -27,14 +27,20 @@ module Async
27
27
  module HTTP1
28
28
  VERSION = "HTTP/1.1"
29
29
 
30
+ def self.bidirectional?
31
+ true
32
+ end
33
+
30
34
  def self.client(stream)
31
- Client.new(stream, VERSION)
35
+ HTTP1::Client.new(stream, VERSION)
32
36
  end
33
37
 
34
- # A server that supports both HTTP1.0 and HTTP1.1 semantics by detecting the version of the request.
35
- # TODO Verify correct behaviour.
36
38
  def self.server(stream)
37
- Server.new(stream, VERSION)
39
+ HTTP1::Server.new(stream, VERSION)
40
+ end
41
+
42
+ def self.names
43
+ ["http/1.1", "http/1.0"]
38
44
  end
39
45
  end
40
46
  end
@@ -53,6 +53,11 @@ module Async
53
53
  # Server loop.
54
54
  def each(task: Task.current)
55
55
  while request = next_request
56
+ Async.logger.debug(self) do |buffer|
57
+ buffer.puts "Incoming request: #{request.authority} #{request.method} #{request.path} #{request.version}"
58
+ buffer.puts "Incoming headers: #{request.headers}"
59
+ end
60
+
56
61
  response = yield(request, self)
57
62
 
58
63
  return if @stream.nil? or @stream.closed?
@@ -37,6 +37,10 @@ module Async
37
37
  def self.server(stream)
38
38
  HTTP1::Server.new(stream, VERSION)
39
39
  end
40
+
41
+ def self.names
42
+ ["http/1.0"]
43
+ end
40
44
  end
41
45
  end
42
46
  end
@@ -37,6 +37,10 @@ module Async
37
37
  def self.server(stream)
38
38
  HTTP1::Server.new(stream, VERSION)
39
39
  end
40
+
41
+ def self.names
42
+ ["http/1.1"]
43
+ end
40
44
  end
41
45
  end
42
46
  end
@@ -63,6 +63,10 @@ module Async
63
63
  return server
64
64
  end
65
65
 
66
+ def self.names
67
+ ["h2"]
68
+ end
69
+
66
70
  module WithPush
67
71
  CLIENT_SETTINGS = HTTP2::CLIENT_SETTINGS.merge(
68
72
  ::Protocol::HTTP2::Settings::ENABLE_PUSH => 1,
@@ -75,6 +79,10 @@ module Async
75
79
  def self.server(stream, settings = SERVER_SETTINGS)
76
80
  HTTP2.server(stream, settings)
77
81
  end
82
+
83
+ def self.names
84
+ HTTP2.names
85
+ end
78
86
  end
79
87
  end
80
88
  end
@@ -124,25 +124,25 @@ module Async
124
124
  VERSION
125
125
  end
126
126
 
127
- def encode_headers(headers, buffer = String.new.b)
128
- super.tap do |data|
129
- Async.logger.debug(self) do |buffer|
130
- buffer.puts "Encode headers: #{headers.inspect}"
131
- buffer.puts "-> #{data.inspect}"
132
- buffer.puts "@encoder: #{@encoder.inspect}"
133
- end
134
- end
135
- end
136
-
137
- def decode_headers(data)
138
- super.tap do |headers|
139
- Async.logger.debug(self) do |buffer|
140
- buffer.puts "Decode headers: #{data.inspect}"
141
- buffer.puts "-> #{headers.inspect}"
142
- buffer.puts "@decoder: #{@decoder.inspect}"
143
- end
144
- end
145
- end
127
+ # def encode_headers(headers, buffer = String.new.b)
128
+ # super.tap do |data|
129
+ # Async.logger.debug(self) do |buffer|
130
+ # buffer.puts "Encode headers: #{headers.inspect}"
131
+ # buffer.puts "-> #{data.inspect}"
132
+ # buffer.puts "@encoder: #{@encoder.inspect}"
133
+ # end
134
+ # end
135
+ # end
136
+ #
137
+ # def decode_headers(data)
138
+ # super.tap do |headers|
139
+ # Async.logger.debug(self) do |buffer|
140
+ # buffer.puts "Decode headers: #{data.inspect}"
141
+ # buffer.puts "-> #{headers.inspect}"
142
+ # buffer.puts "@decoder: #{@decoder.inspect}"
143
+ # end
144
+ # end
145
+ # end
146
146
  end
147
147
  end
148
148
  end
@@ -49,9 +49,9 @@ module Async
49
49
  # A server that supports both HTTP1.0 and HTTP1.1 semantics by detecting the version of the request.
50
50
  module HTTPS
51
51
  HANDLERS = {
52
- "http/1.0" => HTTP10,
53
- "http/1.1" => HTTP11,
54
52
  "h2" => HTTP2,
53
+ "http/1.1" => HTTP11,
54
+ "http/1.0" => HTTP10,
55
55
  nil => HTTP11,
56
56
  }
57
57
 
@@ -75,6 +75,11 @@ module Async
75
75
  def self.server(stream)
76
76
  protocol_for(stream).server(stream)
77
77
  end
78
+
79
+ # Supported Application Layer Protocol Negotiation names:
80
+ def self.names
81
+ HANDLERS.keys.compact
82
+ end
78
83
  end
79
84
  end
80
85
  end
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module HTTP
23
- VERSION = "0.45.9"
23
+ VERSION = "0.46.0"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.45.9
4
+ version: 0.46.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-22 00:00:00.000000000 Z
11
+ date: 2019-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async