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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/async/http/client.rb +1 -1
- data/lib/async/http/internet.rb +8 -0
- data/lib/async/http/protocol/http1/request.rb +4 -1
- data/lib/async/http/protocol/http1/response.rb +3 -1
- data/lib/async/http/protocol/http1/server.rb +51 -45
- data/lib/async/http/protocol/http2.rb +1 -1
- data/lib/async/http/server.rb +1 -1
- data/lib/async/http/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +5 -5
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9c1723c67062bba48acefa3d4c2a5f91a3834b17eb766f2bf215e20bc6c9836
|
4
|
+
data.tar.gz: 85ce6e5ad1d7be8b014c984423de2ff561a25276ba18c4224251718d6c3e5d39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3972ca0631829425e8e13b2abf0460b19ce4d4f0e365e2b12f784c0eaebaf3288aed5315766466529d7f9bae85c5cdfb3a3bfa5bf754095897d9f3ad68f0e8e2
|
7
|
+
data.tar.gz: e35b08e0e192a8920a2cbc077580b0a5135073cc2279d6f5eff96ed5e9549197b8ceb942b773762acb0f753e8a2d037dee5087d3388503b0368b6115fc1c275f
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/async/http/client.rb
CHANGED
data/lib/async/http/internet.rb
CHANGED
@@ -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
|
-
|
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 =
|
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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
-
|
93
|
-
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
|
-
|
101
|
-
#
|
102
|
-
|
103
|
-
|
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
|
data/lib/async/http/server.rb
CHANGED
@@ -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
|
data/lib/async/http/version.rb
CHANGED
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.
|
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-
|
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.
|
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
|