async-http 0.56.0 → 0.56.4

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: 48e39e03d8f8d966cd0b9fa29b04f806011e8a4c735225bc2869accb5189c433
4
- data.tar.gz: c6d938753a924cae643c8b7a627d621a0e37d7227df11ad2cf9baa9c962b46ad
3
+ metadata.gz: caff6f0e39afa2ec8e8eaff86fc960121968f136fd23bee8e4c4344e1da55c36
4
+ data.tar.gz: 8428ae61665e4bc9275cf1a127006c9c975cc184267a1ac0a35b9b7df80d608f
5
5
  SHA512:
6
- metadata.gz: 81d8b0437f1aa6651a0bf730f1646c14962fec6229058cad0a65385e5055931756b30f18eb3f8469b9fdcaf7ed49e50cb50bc53e1a590194463b59adb9ba2dc8
7
- data.tar.gz: dd2c97685a6cef840107421e14e00f2575fc69c00dde5cad7ef8e681cc2bdc0e2705dc4af90fba403cacc5e084534978dc5b67b162b6a9f121aacd7e65a6551f
6
+ metadata.gz: 761f315b4fc933cb92d80eb9000e2f5dd2c796bc9e119265ee452f27f0edabc071766e4d48e35dd1866661d315166b7e32fb509348ec5c9cb43c38c5d1b4586f
7
+ data.tar.gz: 0b229bf87de21d7cc05de022283901f75114bf37acc240e7992430c5e47602ab04f8b9aa76884b30733f55a1b52b0d3ae51b9dc0e25ea1a653dfda680e77a1ce
@@ -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
@@ -21,7 +21,7 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  require_relative '../internet'
24
- require 'thread-local'
24
+ require 'thread/local'
25
25
 
26
26
  module Async
27
27
  module HTTP
@@ -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.0"
25
+ VERSION = "0.56.4"
26
26
  end
27
27
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.56.0
4
+ version: 0.56.4
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
@@ -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.