async-http 0.56.1 → 0.56.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d7ce0d0d3e46cbefd67fdd2064c6a144b8dfda461363462e05ea2bc421a1150
4
- data.tar.gz: '0075078bcb61b68205d0094047df19f38a469b8b545811336a35e3c160bb5880'
3
+ metadata.gz: 7152de875b7dee12eed4876f7a8cd55ce3c091011d87fdc9389fb52bae092686
4
+ data.tar.gz: 812fa1a3eb74072dac8d10fa074c6f442a9017e2f9d65b2f53fe9fd72db0d90d
5
5
  SHA512:
6
- metadata.gz: '061618238094db458acb14c1ce6273af279f0571d5c67b1b49a4cc03d12228c4269e45be544b69edb555a9d304f22564306193bd9205262853285940dd7ccf8b'
7
- data.tar.gz: 63e7b3767a42cc2fc82e81a55bfb5e3aa64ea16d83226a3452b9453266f9bbff1cbef9ea015958d77c89d142ff38f68c8c2b36216df80ad1c7320e868fd0beba
6
+ metadata.gz: 9e3d63e16368697ad7e146b3448cf5b19ae7147db9f65356252dcee05a83fb852e2a03350bbe591eab21a530100d1c3830b9d76758f81e21366c45542a8a5bbb
7
+ data.tar.gz: b9d013071286319e2a45ca85de0dad52fe030f1230319fb68d7ec5f4d1d999e96fbbba23cebf0021ff32c826c597d16c862c834f98d3bb2773f13fb6a56f242d
@@ -26,7 +26,7 @@ def server
26
26
 
27
27
  container = Async::Container.new
28
28
 
29
- Async.logger.info(self){"Starting server..."}
29
+ Console.logger.info(self){"Starting server..."}
30
30
 
31
31
  container.run(count: 1) do
32
32
  server = Async::HTTP::Server.for(endpoint, protocol: Async::HTTP::Protocol::HTTP2, scheme: "https") do |request|
@@ -83,7 +83,7 @@ module Async
83
83
 
84
84
  def close
85
85
  while @pool.busy?
86
- Async.logger.warn(self) {"Waiting for #{@protocol} pool to drain: #{@pool}"}
86
+ Console.logger.warn(self) {"Waiting for #{@protocol} pool to drain: #{@pool}"}
87
87
  @pool.wait
88
88
  end
89
89
 
@@ -152,7 +152,7 @@ module Async
152
152
 
153
153
  def make_pool(connection_limit)
154
154
  Async::Pool::Controller.wrap(limit: connection_limit) do
155
- Async.logger.debug(self) {"Making connection to #{@endpoint.inspect}"}
155
+ Console.logger.debug(self) {"Making connection to #{@endpoint.inspect}"}
156
156
 
157
157
  @protocol.client(@endpoint.connect)
158
158
  end
@@ -31,7 +31,7 @@ module Async
31
31
  module HTTP
32
32
  class Internet
33
33
  def initialize(**options)
34
- @clients = {}
34
+ @clients = Hash.new
35
35
  @options = options
36
36
  end
37
37
 
@@ -39,13 +39,17 @@ module Async
39
39
  # @attribute [Hash(URI, Client)]
40
40
  attr :clients
41
41
 
42
- def call(method, url, headers = nil, body = nil)
43
- endpoint = Endpoint.parse(url)
42
+ def client_for(endpoint)
44
43
  key = host_key(endpoint)
45
44
 
46
- client = @clients.fetch(key) do
47
- @clients[key] = self.client_for(endpoint)
45
+ @clients.fetch(key) do
46
+ @clients[key] = self.make_client(endpoint)
48
47
  end
48
+ end
49
+
50
+ def call(method, url, headers = nil, body = nil)
51
+ endpoint = Endpoint.parse(url)
52
+ client = self.client_for(endpoint)
49
53
 
50
54
  body = Body::Buffered.wrap(body)
51
55
  headers = ::Protocol::HTTP::Headers[headers]
@@ -55,12 +59,6 @@ module Async
55
59
  return client.call(request)
56
60
  end
57
61
 
58
- def client_for(endpoint)
59
- ::Protocol::HTTP::AcceptEncoding.new(
60
- Client.new(endpoint, **@options)
61
- )
62
- end
63
-
64
62
  def close
65
63
  # The order of operations here is to avoid a race condition between iterating over clients (#close may yield) and creating new clients.
66
64
  clients = @clients.values
@@ -75,7 +73,13 @@ module Async
75
73
  end
76
74
  end
77
75
 
78
- private
76
+ protected
77
+
78
+ def make_client(endpoint)
79
+ ::Protocol::HTTP::AcceptEncoding.new(
80
+ Client.new(endpoint, **@options)
81
+ )
82
+ end
79
83
 
80
84
  def host_key(endpoint)
81
85
  url = endpoint.url.dup
@@ -29,7 +29,10 @@ module Async
29
29
  class Client < Connection
30
30
  # Used by the client to send requests to the remote server.
31
31
  def call(request, task: Task.current)
32
- Async.logger.debug(self) {"#{request.method} #{request.path} #{request.headers.inspect}"}
32
+ # We need to keep track of connections which are not in the initial "ready" state.
33
+ @ready = false
34
+
35
+ Console.logger.debug(self) {"#{request.method} #{request.path} #{request.headers.inspect}"}
33
36
 
34
37
  trailer = request.headers.trailer!
35
38
 
@@ -72,7 +75,10 @@ module Async
72
75
  write_body(@version, body, false, trailer)
73
76
  end
74
77
 
75
- return Response.read(self, request)
78
+ response = Response.read(self, request)
79
+ @ready = true
80
+
81
+ return response
76
82
  rescue
77
83
  # This will ensure that #reusable? returns false.
78
84
  @stream.close
@@ -33,6 +33,7 @@ module Async
33
33
  def initialize(stream, version)
34
34
  super(stream)
35
35
 
36
+ @ready = true
36
37
  @version = version
37
38
  end
38
39
 
@@ -48,8 +49,6 @@ module Async
48
49
 
49
50
  def read_line?
50
51
  @stream.read_until(CRLF)
51
- rescue Errno::ECONNRESET
52
- return nil
53
52
  end
54
53
 
55
54
  def read_line
@@ -68,11 +67,11 @@ module Async
68
67
 
69
68
  # Can we use this connection to make requests?
70
69
  def viable?
71
- @stream&.connected?
70
+ @ready && @stream&.connected?
72
71
  end
73
72
 
74
73
  def reusable?
75
- @persistent && @stream && !@stream.closed?
74
+ @ready && @persistent && @stream && !@stream.closed?
76
75
  end
77
76
  end
78
77
  end
@@ -88,7 +88,7 @@ module Async
88
88
  @input = nil
89
89
  end
90
90
  rescue ::Protocol::HTTP2::HeaderError => error
91
- Async.logger.error(self, error)
91
+ Console.logger.error(self, error)
92
92
 
93
93
  send_reset_stream(error.code)
94
94
  end
@@ -59,7 +59,7 @@ module Async
59
59
  # alpn_protocol is only available if openssl v1.0.2+
60
60
  name = peer.alpn_protocol
61
61
 
62
- Async.logger.debug(self) {"Negotiating protocol #{name.inspect}..."}
62
+ Console.logger.debug(self) {"Negotiating protocol #{name.inspect}..."}
63
63
 
64
64
  if protocol = HANDLERS[name]
65
65
  return protocol
@@ -48,7 +48,7 @@ module Async
48
48
  def accept(peer, address, task: Task.current)
49
49
  connection = @protocol.server(peer)
50
50
 
51
- Async.logger.debug(self) {"Incoming connnection from #{address.inspect} to #{@protocol}"}
51
+ Console.logger.debug(self) {"Incoming connnection from #{address.inspect} to #{@protocol}"}
52
52
 
53
53
  connection.each do |request|
54
54
  # We set the default scheme unless it was otherwise specified.
@@ -58,7 +58,7 @@ module Async
58
58
  # This is a slight optimization to avoid having to get the address from the socket.
59
59
  request.remote_address = address
60
60
 
61
- # Async.logger.debug(self) {"Incoming request from #{address.inspect}: #{request.method} #{request.path}"}
61
+ # Console.logger.debug(self) {"Incoming request from #{address.inspect}: #{request.method} #{request.path}"}
62
62
 
63
63
  # If this returns nil, we assume that the connection has been hijacked.
64
64
  self.call(request)
@@ -22,6 +22,6 @@
22
22
 
23
23
  module Async
24
24
  module HTTP
25
- VERSION = "0.56.1"
25
+ VERSION = "0.56.5"
26
26
  end
27
27
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.56.1
4
+ version: 0.56.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-23 00:00:00.000000000 Z
11
+ date: 2021-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.25'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.25'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: async-io
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.28'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.28'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: async-pool
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0.2'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.2'
55
55
  - !ruby/object:Gem::Dependency
@@ -244,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
244
244
  - !ruby/object:Gem::Version
245
245
  version: '0'
246
246
  requirements: []
247
- rubygems_version: 3.1.2
247
+ rubygems_version: 3.2.22
248
248
  signing_key:
249
249
  specification_version: 4
250
250
  summary: A HTTP client and server library.