async-http 0.55.0 → 0.56.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bake/async/http.rb +2 -2
- data/lib/async/http/internet.rb +6 -2
- data/lib/async/http/internet/instance.rb +33 -0
- data/lib/async/http/protocol/http1.rb +1 -1
- data/lib/async/http/protocol/http1/client.rb +3 -3
- data/lib/async/http/protocol/http1/server.rb +2 -2
- data/lib/async/http/protocol/http10.rb +1 -1
- data/lib/async/http/protocol/http11.rb +1 -1
- data/lib/async/http/protocol/http2.rb +1 -1
- data/lib/async/http/protocol/http2/connection.rb +1 -1
- data/lib/async/http/protocol/http2/output.rb +3 -3
- data/lib/async/http/protocol/http2/request.rb +3 -3
- data/lib/async/http/protocol/http2/response.rb +3 -3
- data/lib/async/http/protocol/http2/stream.rb +10 -10
- data/lib/async/http/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48e39e03d8f8d966cd0b9fa29b04f806011e8a4c735225bc2869accb5189c433
|
4
|
+
data.tar.gz: c6d938753a924cae643c8b7a627d621a0e37d7227df11ad2cf9baa9c962b46ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81d8b0437f1aa6651a0bf730f1646c14962fec6229058cad0a65385e5055931756b30f18eb3f8469b9fdcaf7ed49e50cb50bc53e1a590194463b59adb9ba2dc8
|
7
|
+
data.tar.gz: dd2c97685a6cef840107421e14e00f2575fc69c00dde5cad7ef8e681cc2bdc0e2705dc4af90fba403cacc5e084534978dc5b67b162b6a9f121aacd7e65a6551f
|
data/bake/async/http.rb
CHANGED
@@ -68,8 +68,8 @@ def fetch(url, method:)
|
|
68
68
|
|
69
69
|
response.finish
|
70
70
|
|
71
|
-
if
|
72
|
-
|
71
|
+
if trailer = response.headers.trailer
|
72
|
+
trailer.each do |key, value|
|
73
73
|
terminal.print_line(
|
74
74
|
:key, key.rjust(align), :reset, ": ", :value, value.inspect
|
75
75
|
)
|
data/lib/async/http/internet.rb
CHANGED
@@ -22,8 +22,10 @@
|
|
22
22
|
|
23
23
|
require_relative 'client'
|
24
24
|
require_relative 'endpoint'
|
25
|
+
|
25
26
|
require 'protocol/http/middleware'
|
26
27
|
require 'protocol/http/body/buffered'
|
28
|
+
require 'protocol/http/accept_encoding'
|
27
29
|
|
28
30
|
module Async
|
29
31
|
module HTTP
|
@@ -48,13 +50,15 @@ module Async
|
|
48
50
|
body = Body::Buffered.wrap(body)
|
49
51
|
headers = ::Protocol::HTTP::Headers[headers]
|
50
52
|
|
51
|
-
request = ::Protocol::HTTP::Request.new(
|
53
|
+
request = ::Protocol::HTTP::Request.new(endpoint.scheme, endpoint.authority, method, endpoint.path, nil, headers, body)
|
52
54
|
|
53
55
|
return client.call(request)
|
54
56
|
end
|
55
57
|
|
56
58
|
def client_for(endpoint)
|
57
|
-
|
59
|
+
::Protocol::HTTP::AcceptEncoding.new(
|
60
|
+
Client.new(endpoint, **@options)
|
61
|
+
)
|
58
62
|
end
|
59
63
|
|
60
64
|
def close
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
require_relative '../internet'
|
24
|
+
require 'thread-local'
|
25
|
+
|
26
|
+
module Async
|
27
|
+
module HTTP
|
28
|
+
class Internet
|
29
|
+
# Provide access to a shared thread-local instance.
|
30
|
+
extend ::Thread::Local
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -31,7 +31,7 @@ module Async
|
|
31
31
|
def call(request, task: Task.current)
|
32
32
|
Async.logger.debug(self) {"#{request.method} #{request.path} #{request.headers.inspect}"}
|
33
33
|
|
34
|
-
|
34
|
+
trailer = request.headers.trailer!
|
35
35
|
|
36
36
|
# We carefully interpret https://tools.ietf.org/html/rfc7230#section-6.3.1 to implement this correctly.
|
37
37
|
begin
|
@@ -63,13 +63,13 @@ module Async
|
|
63
63
|
subtask.annotate("Streaming body.")
|
64
64
|
|
65
65
|
# Once we start writing the body, we can't recover if the request fails. That's because the body might be generated dynamically, streaming, etc.
|
66
|
-
write_body(@version, body, false,
|
66
|
+
write_body(@version, body, false, trailer)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
elsif protocol = request.protocol
|
70
70
|
write_upgrade_body(protocol)
|
71
71
|
else
|
72
|
-
write_body(@version, body, false,
|
72
|
+
write_body(@version, body, false, trailer)
|
73
73
|
end
|
74
74
|
|
75
75
|
return Response.read(self, request)
|
@@ -64,7 +64,7 @@ module Async
|
|
64
64
|
return if @stream.nil? or @stream.closed?
|
65
65
|
|
66
66
|
if response
|
67
|
-
|
67
|
+
trailer = response.headers.trailer!
|
68
68
|
|
69
69
|
write_response(@version, response.status, response.headers)
|
70
70
|
|
@@ -95,7 +95,7 @@ module Async
|
|
95
95
|
request = nil unless body
|
96
96
|
response = nil
|
97
97
|
|
98
|
-
write_body(version, body, head,
|
98
|
+
write_body(version, body, head, trailer)
|
99
99
|
end
|
100
100
|
else
|
101
101
|
# If the request failed to generate a response, it was an internal server error:
|
@@ -27,17 +27,17 @@ module Async
|
|
27
27
|
module Protocol
|
28
28
|
module HTTP2
|
29
29
|
class Output
|
30
|
-
def initialize(stream, body,
|
30
|
+
def initialize(stream, body, trailer = nil)
|
31
31
|
@stream = stream
|
32
32
|
@body = body
|
33
|
-
@
|
33
|
+
@trailer = trailer
|
34
34
|
|
35
35
|
@task = nil
|
36
36
|
|
37
37
|
@window_updated = Async::Condition.new
|
38
38
|
end
|
39
39
|
|
40
|
-
attr :
|
40
|
+
attr :trailer
|
41
41
|
|
42
42
|
def start(parent: Task.current)
|
43
43
|
raise "Task already started!" if @task
|
@@ -145,12 +145,12 @@ module Async
|
|
145
145
|
headers = ::Protocol::HTTP::Headers::Merged.new(protocol_headers, response.headers)
|
146
146
|
|
147
147
|
if body = response.body and !self.head?
|
148
|
-
# This function informs the headers object that any subsequent headers are going to be
|
149
|
-
|
148
|
+
# This function informs the headers object that any subsequent headers are going to be trailer. Therefore, it must be called *before* sending the headers, to avoid any race conditions.
|
149
|
+
trailer = response.headers.trailer!
|
150
150
|
|
151
151
|
@stream.send_headers(nil, headers)
|
152
152
|
|
153
|
-
@stream.send_body(body,
|
153
|
+
@stream.send_body(body, trailer)
|
154
154
|
else
|
155
155
|
# Ensure the response body is closed if we are ending the stream:
|
156
156
|
response.close
|
@@ -208,8 +208,8 @@ module Async
|
|
208
208
|
pseudo_headers << [CONTENT_LENGTH, length]
|
209
209
|
end
|
210
210
|
|
211
|
-
# This function informs the headers object that any subsequent headers are going to be
|
212
|
-
|
211
|
+
# This function informs the headers object that any subsequent headers are going to be trailer. Therefore, it must be called *before* sending the headers, to avoid any race conditions.
|
212
|
+
trailer = request.headers.trailer!
|
213
213
|
|
214
214
|
begin
|
215
215
|
@stream.send_headers(nil, headers)
|
@@ -217,7 +217,7 @@ module Async
|
|
217
217
|
raise RequestFailed
|
218
218
|
end
|
219
219
|
|
220
|
-
@stream.send_body(request.body,
|
220
|
+
@stream.send_body(request.body, trailer)
|
221
221
|
end
|
222
222
|
end
|
223
223
|
end
|
@@ -34,7 +34,7 @@ module Async
|
|
34
34
|
super
|
35
35
|
|
36
36
|
@headers = nil
|
37
|
-
@
|
37
|
+
@trailer = nil
|
38
38
|
|
39
39
|
# Input buffer, reading request body, or response body (receive_data):
|
40
40
|
@length = nil
|
@@ -62,7 +62,7 @@ module Async
|
|
62
62
|
|
63
63
|
def receive_trailing_headers(headers, end_stream)
|
64
64
|
headers.each do |key, value|
|
65
|
-
if @
|
65
|
+
if @trailer.include?(key)
|
66
66
|
add_header(key, value)
|
67
67
|
else
|
68
68
|
raise ::Protocol::HTTP2::HeaderError, "Cannot add trailer #{key} as it was not specified as a trailer!"
|
@@ -75,8 +75,8 @@ module Async
|
|
75
75
|
@headers = ::Protocol::HTTP::Headers.new
|
76
76
|
self.receive_initial_headers(super, frame.end_stream?)
|
77
77
|
|
78
|
-
@
|
79
|
-
elsif @
|
78
|
+
@trailer = @headers[TRAILER]
|
79
|
+
elsif @trailer and frame.end_stream?
|
80
80
|
self.receive_trailing_headers(super, frame.end_stream?)
|
81
81
|
else
|
82
82
|
raise ::Protocol::HTTP2::HeaderError, "Unable to process headers!"
|
@@ -136,24 +136,24 @@ module Async
|
|
136
136
|
end
|
137
137
|
|
138
138
|
# Set the body and begin sending it.
|
139
|
-
def send_body(body,
|
140
|
-
@output = Output.new(self, body,
|
139
|
+
def send_body(body, trailer = nil)
|
140
|
+
@output = Output.new(self, body, trailer)
|
141
141
|
|
142
142
|
@output.start
|
143
143
|
end
|
144
144
|
|
145
145
|
# Called when the output terminates normally.
|
146
146
|
def finish_output(error = nil)
|
147
|
-
|
147
|
+
trailer = @output&.trailer
|
148
148
|
|
149
149
|
@output = nil
|
150
150
|
|
151
151
|
if error
|
152
152
|
send_reset_stream(::Protocol::HTTP2::Error::INTERNAL_ERROR)
|
153
153
|
else
|
154
|
-
# Write
|
155
|
-
if
|
156
|
-
send_headers(nil,
|
154
|
+
# Write trailer?
|
155
|
+
if trailer
|
156
|
+
send_headers(nil, trailer, ::Protocol::HTTP2::END_STREAM)
|
157
157
|
else
|
158
158
|
send_data(nil, ::Protocol::HTTP2::END_STREAM)
|
159
159
|
end
|
data/lib/async/http/version.rb
CHANGED
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.
|
4
|
+
version: 0.56.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: 2021-04-
|
11
|
+
date: 2021-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|
@@ -58,28 +58,28 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
61
|
+
version: 0.22.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.
|
68
|
+
version: 0.22.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: protocol-http1
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
75
|
+
version: 0.14.0
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
82
|
+
version: 0.14.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: protocol-http2
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -197,6 +197,7 @@ files:
|
|
197
197
|
- lib/async/http/client.rb
|
198
198
|
- lib/async/http/endpoint.rb
|
199
199
|
- lib/async/http/internet.rb
|
200
|
+
- lib/async/http/internet/instance.rb
|
200
201
|
- lib/async/http/protocol.rb
|
201
202
|
- lib/async/http/protocol/http1.rb
|
202
203
|
- lib/async/http/protocol/http1/client.rb
|
@@ -243,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
243
244
|
- !ruby/object:Gem::Version
|
244
245
|
version: '0'
|
245
246
|
requirements: []
|
246
|
-
rubygems_version: 3.2
|
247
|
+
rubygems_version: 3.1.2
|
247
248
|
signing_key:
|
248
249
|
specification_version: 4
|
249
250
|
summary: A HTTP client and server library.
|