async-http 0.57.0 → 0.59.1

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: 454a678139fa72fafb6fc06cc34af7f21b44bba2a7ebddf7bfc823c01c5b968a
4
- data.tar.gz: d91f30582707db6bd9a717d449c7d8295f8110b315defec4477b892e28678c22
3
+ metadata.gz: f9c1723c67062bba48acefa3d4c2a5f91a3834b17eb766f2bf215e20bc6c9836
4
+ data.tar.gz: 85ce6e5ad1d7be8b014c984423de2ff561a25276ba18c4224251718d6c3e5d39
5
5
  SHA512:
6
- metadata.gz: 0517cac618b852dca972400c943b7fc78ee7693ad1555eeb2699d5fc45a6fee0d4ceeb45121168955da3bdd980ebee788f21c51d42e3de5fba03a8896e3fb3fc
7
- data.tar.gz: 321e705b70ab0efb1d36cc8614a6193b593c930badd96f239734685594da3456ee505e9dcc9c7fe28fc4ace349c25e4cff3774b5753d1c692769b21466d80de4
6
+ metadata.gz: 3972ca0631829425e8e13b2abf0460b19ce4d4f0e365e2b12f784c0eaebaf3288aed5315766466529d7f9bae85c5cdfb3a3bfa5bf754095897d9f3ad68f0e8e2
7
+ data.tar.gz: e35b08e0e192a8920a2cbc077580b0a5135073cc2279d6f5eff96ed5e9549197b8ceb942b773762acb0f753e8a2d037dee5087d3388503b0368b6115fc1c275f
checksums.yaml.gz.sig CHANGED
Binary file
@@ -138,7 +138,7 @@ module Async
138
138
  @pool.release(connection) if connection
139
139
  end
140
140
  end
141
-
141
+
142
142
  def inspect
143
143
  "#<#{self.class} authority=#{@authority.inspect}>"
144
144
  end
@@ -47,6 +47,14 @@ module Async
47
47
  end
48
48
  end
49
49
 
50
+ # Make a request to the internet with the given `method` and `url`.
51
+ #
52
+ # If you provide non-frozen headers, they may be mutated.
53
+ #
54
+ # @parameter method [String] The request method, e.g. `GET`.
55
+ # @parameter url [String] The URL to request, e.g. `https://www.codeotaku.com`.
56
+ # @parameter headers [Hash | Protocol::HTTP::Headers] The headers to send with the request.
57
+ # @parameter body [String | Protocol::HTTP::Body] The body to send with the request.
50
58
  def call(method, url, headers = nil, body = nil)
51
59
  endpoint = Endpoint.parse(url)
52
60
  client = self.client_for(endpoint)
@@ -32,11 +32,14 @@ module Async
32
32
  self.new(connection, *parts)
33
33
  end
34
34
  end
35
+
36
+ UPGRADE = 'upgrade'
35
37
 
36
38
  def initialize(connection, authority, method, path, version, headers, body)
37
39
  @connection = connection
38
40
 
39
- protocol = connection.upgrade?(headers)
41
+ # HTTP/1 requests with an upgrade header (which can contain zero or more values) are extracted into the protocol field of the request, and we expect a response to select one of those protocols with a status code of 101 Switching Protocols.
42
+ protocol = headers.delete('upgrade')
40
43
 
41
44
  super(nil, authority, method, path, version, headers, body, protocol)
42
45
  end
@@ -33,11 +33,13 @@ module Async
33
33
  end
34
34
  end
35
35
 
36
+ UPGRADE = 'upgrade'
37
+
36
38
  # @param reason [String] HTTP response line reason, ignored.
37
39
  def initialize(connection, version, status, reason, headers, body)
38
40
  @connection = connection
39
41
 
40
- protocol = connection.upgrade?(headers)
42
+ protocol = headers.delete(UPGRADE)
41
43
 
42
44
  super(version, status, headers, body, protocol)
43
45
  end
@@ -60,54 +60,60 @@ module Async
60
60
 
61
61
  while request = next_request
62
62
  response = yield(request, self)
63
-
64
- return if @stream.nil? or @stream.closed?
65
-
66
- if response
67
- trailer = response.headers.trailer!
68
-
69
- write_response(@version, response.status, response.headers)
70
-
71
- body = response.body
72
-
73
- if body and protocol = response.protocol
74
- stream = write_upgrade_body(protocol)
75
-
76
- # At this point, the request body is hijacked, so we don't want to call #finish below.
77
- request = nil
78
-
79
- # We also don't want to hold on to the response object:
80
- response = nil
81
-
82
- body.call(stream)
83
- elsif request.connect? and response.success?
84
- stream = write_tunnel_body(request.version)
85
-
86
- # Same as above:
87
- request = nil
88
- response = nil
89
-
90
- body.call(stream)
63
+ body = response&.body
64
+
65
+ begin
66
+ # If a response was generated, send it:
67
+ if response
68
+ trailer = response.headers.trailer!
69
+
70
+ write_response(@version, response.status, response.headers)
71
+
72
+ # Some operations in this method are long running, that is, it's expected that `body.call(stream)` could literally run indefinitely. In order to facilitate garbage collection, we want to nullify as many local variables before calling the streaming body. This ensures that the garbage collection can clean up as much state as possible during the long running operation, so we don't retain objects that are no longer needed.
73
+
74
+ if body and protocol = response.protocol
75
+ stream = write_upgrade_body(protocol)
76
+
77
+ # At this point, the request body is hijacked, so we don't want to call #finish below.
78
+ request = response = nil
79
+
80
+ body.call(stream)
81
+ elsif request.connect? and response.success?
82
+ stream = write_tunnel_body(request.version)
83
+
84
+ # Same as above:
85
+ request = response = nil
86
+
87
+ body.call(stream)
88
+ else
89
+ head = request.head?
90
+ version = request.version
91
+
92
+ # Same as above:
93
+ request = nil unless body
94
+ response = nil
95
+
96
+ write_body(version, body, head, trailer)
97
+ end
98
+
99
+ # We are done with the body, you shouldn't need to call close on it:
100
+ body = nil
91
101
  else
92
- head = request.head?
93
- version = request.version
94
-
95
- request = nil unless body
96
- response = nil
97
-
98
- write_body(version, body, head, trailer)
102
+ # If the request failed to generate a response, it was an internal server error:
103
+ write_response(@version, 500, {})
104
+ write_body(request.version, nil)
99
105
  end
100
- else
101
- # If the request failed to generate a response, it was an internal server error:
102
- write_response(@version, 500, {})
103
- write_body(request.version, nil)
106
+
107
+ # Gracefully finish reading the request body if it was not already done so.
108
+ request&.finish
109
+
110
+ # This ensures we yield at least once every iteration of the loop and allow other fibers to execute.
111
+ task.yield
112
+ rescue => error
113
+ raise
114
+ ensure
115
+ body&.close(error)
104
116
  end
105
-
106
- # Gracefully finish reading the request body if it was not already done so.
107
- request&.finish
108
-
109
- # This ensures we yield at least once every iteration of the loop and allow other fibers to execute.
110
- task.yield
111
117
  end
112
118
  end
113
119
  end
@@ -27,7 +27,7 @@ module Async
27
27
  module HTTP
28
28
  module Protocol
29
29
  module HTTP2
30
- VERSION = "h2"
30
+ VERSION = "HTTP/2"
31
31
 
32
32
  def self.bidirectional?
33
33
  true
@@ -96,7 +96,7 @@ module Async
96
96
  attributes['http.protocol'] = protocol
97
97
  end
98
98
 
99
- trace('async.http.server.call', attributes: attributes) do |span|
99
+ trace('async.http.server.call', resource: "#{request.method} #{request.path}", attributes: attributes) do |span|
100
100
  super.tap do |response|
101
101
  if status = response&.status
102
102
  span['http.status_code'] = status
@@ -22,6 +22,6 @@
22
22
 
23
23
  module Async
24
24
  module HTTP
25
- VERSION = "0.57.0"
25
+ VERSION = "0.59.1"
26
26
  end
27
27
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.57.0
4
+ version: 0.59.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -52,7 +52,7 @@ cert_chain:
52
52
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
53
53
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
54
54
  -----END CERTIFICATE-----
55
- date: 2022-08-07 00:00:00.000000000 Z
55
+ date: 2022-08-17 00:00:00.000000000 Z
56
56
  dependencies:
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: async
@@ -142,14 +142,14 @@ dependencies:
142
142
  name: traces
143
143
  requirement: !ruby/object:Gem::Requirement
144
144
  requirements:
145
- - - "~>"
145
+ - - ">="
146
146
  - !ruby/object:Gem::Version
147
147
  version: 0.4.0
148
148
  type: :runtime
149
149
  prerelease: false
150
150
  version_requirements: !ruby/object:Gem::Requirement
151
151
  requirements:
152
- - - "~>"
152
+ - - ">="
153
153
  - !ruby/object:Gem::Version
154
154
  version: 0.4.0
155
155
  - !ruby/object:Gem::Dependency
@@ -301,7 +301,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
301
301
  - !ruby/object:Gem::Version
302
302
  version: '0'
303
303
  requirements: []
304
- rubygems_version: 3.3.7
304
+ rubygems_version: 3.1.6
305
305
  signing_key:
306
306
  specification_version: 4
307
307
  summary: A HTTP client and server library.
metadata.gz.sig CHANGED
Binary file