async-http 0.50.12 → 0.50.13

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: c270148e0c2c9fee8ac667bdf49a1b41e85cfbf1d15c29299bdc8b2c9a78d94b
4
- data.tar.gz: 2286c4358edf44bb123d0048769f6ddbce3852b27d84bf2fbe3c210e5f43f7ea
3
+ metadata.gz: 2cecbbc1a65dc4e0697fab222184c9a310bdaccfb5673f2200c3686f77ab7b9e
4
+ data.tar.gz: 88a4d5a5b7c10f48033f78ac838c0b75d969f85a33e9ccca07bd0f587865d8ab
5
5
  SHA512:
6
- metadata.gz: dae66750a592681dd68afc1ff146a313289cbeb9d31bce40cd2817e820227385317d36081d56b4d98a28b565b2bba5c3c107d0b7b5f8fd5880b595bd28209c36
7
- data.tar.gz: e92a967b4a857ac3deeb311184e79a0f8ba84343f3bc4bde7e39668a0d2ff32bcd6405f691e5f44476568dfee10b56ff4ce2fb829ac1d4661d702d48b702cf91
6
+ metadata.gz: 9f1bb76e135ec8d00508c5c1625d017e79ba87a19552ea4968b3a206f65fb3702623b2f1d96f80a88948ccbf959e3aac8a959dcc5c86a3cd65cd9159a9b6ac15
7
+ data.tar.gz: b8ea5b50c9a4b76ddf9cd21484eba947674c590410e7335b10c24823997fa9d9c7235e160ee9d804905083e31ee51dca83faea02265421734da35227a9bf7bb0
@@ -21,8 +21,8 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency("async-io", "~> 1.28")
22
22
  spec.add_dependency("async-pool", "~> 0.2")
23
23
 
24
- spec.add_dependency("protocol-http", "~> 0.16.0")
25
- spec.add_dependency("protocol-http1", "~> 0.10.0")
24
+ spec.add_dependency("protocol-http", "~> 0.17.0")
25
+ spec.add_dependency("protocol-http1", "~> 0.11.0")
26
26
  spec.add_dependency("protocol-http2", "~> 0.13.0")
27
27
 
28
28
  # spec.add_dependency("openssl")
@@ -67,6 +67,15 @@ def fetch(url, method:)
67
67
  end
68
68
 
69
69
  response.finish
70
+
71
+ if trailers = response.headers.trailers
72
+ trailers.each do |key, value|
73
+ terminal.print_line(
74
+ :key, key.rjust(align), :reset, ": ", :value, value.inspect
75
+ )
76
+ end
77
+ end
78
+
70
79
  internet.close
71
80
  end
72
81
  end
@@ -33,6 +33,10 @@ module Async
33
33
  true
34
34
  end
35
35
 
36
+ def self.trailers?
37
+ true
38
+ end
39
+
36
40
  def self.client(peer)
37
41
  stream = IO::Stream.new(peer, sync: false)
38
42
 
@@ -39,6 +39,8 @@ module Async
39
39
  raise RequestFailed
40
40
  end
41
41
 
42
+ request.headers.trailers!
43
+
42
44
  if request.body?
43
45
  body = request.body
44
46
 
@@ -61,7 +63,7 @@ module Async
61
63
  subtask.annotate("Streaming body.")
62
64
 
63
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.
64
- write_body(@version, body)
66
+ write_body(@version, body, false, request.trailers)
65
67
  end
66
68
  end
67
69
  elsif protocol = request.protocol
@@ -61,6 +61,7 @@ module Async
61
61
 
62
62
  if response
63
63
  write_response(@version, response.status, response.headers)
64
+ response.headers.trailers!
64
65
 
65
66
  body = response.body
66
67
 
@@ -84,11 +85,12 @@ module Async
84
85
  body.call(stream)
85
86
  else
86
87
  head = request.head?
88
+ trailers = response.trailers
87
89
 
88
90
  request = nil unless body
89
91
  response = nil
90
92
 
91
- write_body(@version, body, head)
93
+ write_body(@version, body, head, trailers)
92
94
  end
93
95
  else
94
96
  # If the request failed to generate a response, it was an internal server error:
@@ -32,6 +32,10 @@ module Async
32
32
  false
33
33
  end
34
34
 
35
+ def self.trailers?
36
+ false
37
+ end
38
+
35
39
  def self.client(peer)
36
40
  stream = IO::Stream.new(peer, sync: false)
37
41
 
@@ -32,6 +32,10 @@ module Async
32
32
  true
33
33
  end
34
34
 
35
+ def self.trailers?
36
+ true
37
+ end
38
+
35
39
  def self.client(peer)
36
40
  stream = IO::Stream.new(peer, sync: false)
37
41
 
@@ -33,6 +33,10 @@ module Async
33
33
  true
34
34
  end
35
35
 
36
+ def self.trailers?
37
+ true
38
+ end
39
+
36
40
  CLIENT_SETTINGS = {
37
41
  ::Protocol::HTTP2::Settings::ENABLE_PUSH => 0,
38
42
  ::Protocol::HTTP2::Settings::MAXIMUM_FRAME_SIZE => 0x100000,
@@ -27,22 +27,18 @@ module Async
27
27
  module Protocol
28
28
  module HTTP2
29
29
  class Output
30
- def self.for(stream, body)
31
- output = self.new(stream, body)
32
-
33
- output.start
34
-
35
- return output
36
- end
37
-
38
- def initialize(stream, body)
30
+ def initialize(stream, body, trailers = nil)
39
31
  @stream = stream
40
32
  @body = body
33
+ @trailers = trailers
34
+
41
35
  @task = nil
42
36
 
43
37
  @window_updated = Async::Condition.new
44
38
  end
45
39
 
40
+ attr :trailers
41
+
46
42
  def start(parent: Task.current)
47
43
  raise "Task already started!" if @task
48
44
 
@@ -184,7 +184,7 @@ module Async
184
184
 
185
185
  if body = response.body and !self.head?
186
186
  @stream.send_headers(nil, headers)
187
- @stream.send_body(body)
187
+ @stream.send_body(body, response.trailers)
188
188
  else
189
189
  # Ensure the response body is closed if we are ending the stream:
190
190
  response.close
@@ -221,7 +221,7 @@ module Async
221
221
  raise RequestFailed
222
222
  end
223
223
 
224
- @stream.send_body(request.body)
224
+ @stream.send_body(request.body, request.trailers)
225
225
  end
226
226
  end
227
227
  end
@@ -60,17 +60,15 @@ module Async
60
60
  end
61
61
  end
62
62
 
63
- def add_trailer(key, value)
64
- if @trailers.include(key)
65
- add_header(key, value)
66
- else
67
- raise ::Protocol::HTTP2::HeaderError, "Cannot add trailer #{key} as it was not specified in trailers!"
68
- end
69
- end
70
-
71
63
  def receive_trailing_headers(headers, end_stream)
64
+ @headers.trailers!
65
+
72
66
  headers.each do |key, value|
73
- add_trailer(key, value)
67
+ if @trailers.include?(key)
68
+ add_header(key, value)
69
+ else
70
+ raise ::Protocol::HTTP2::HeaderError, "Cannot add trailer #{key} as it was not specified as a trailer!"
71
+ end
74
72
  end
75
73
  end
76
74
 
@@ -84,6 +82,12 @@ module Async
84
82
  else
85
83
  raise ::Protocol::HTTP2::HeaderError, "Unable to process headers!"
86
84
  end
85
+
86
+ # TODO this might need to be in an ensure block:
87
+ if @input and frame.end_stream?
88
+ @input.close($!)
89
+ @input = nil
90
+ end
87
91
  rescue ::Protocol::HTTP2::HeaderError => error
88
92
  Async.logger.error(self, error)
89
93
 
@@ -133,18 +137,27 @@ module Async
133
137
  end
134
138
 
135
139
  # Set the body and begin sending it.
136
- def send_body(body)
137
- @output = Output.for(self, body)
140
+ def send_body(body, trailers = nil)
141
+ @output = Output.new(self, body, trailers)
142
+
143
+ @output.start
138
144
  end
139
145
 
140
146
  # Called when the output terminates normally.
141
147
  def finish_output(error = nil)
148
+ trailers = @output&.trailers
149
+
142
150
  @output = nil
143
151
 
144
152
  if error
145
153
  send_reset_stream(::Protocol::HTTP2::Error::INTERNAL_ERROR)
146
154
  else
147
- send_data(nil, ::Protocol::HTTP2::END_STREAM)
155
+ # Write trailers?
156
+ if trailers
157
+ send_headers(nil, trailers, ::Protocol::HTTP2::END_STREAM)
158
+ else
159
+ send_data(nil, ::Protocol::HTTP2::END_STREAM)
160
+ end
148
161
  end
149
162
  end
150
163
 
@@ -168,6 +181,9 @@ module Async
168
181
 
169
182
  if @output
170
183
  @output.stop(error)
184
+
185
+ Async.logger.warn(self) {"Closed output: #{@output}"}
186
+
171
187
  @output = nil
172
188
  end
173
189
 
@@ -22,6 +22,6 @@
22
22
 
23
23
  module Async
24
24
  module HTTP
25
- VERSION = "0.50.12"
25
+ VERSION = "0.50.13"
26
26
  end
27
27
  end
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.50.12
4
+ version: 0.50.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-05 00:00:00.000000000 Z
11
+ date: 2020-04-07 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.16.0
61
+ version: 0.17.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.16.0
68
+ version: 0.17.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.10.0
75
+ version: 0.11.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.10.0
82
+ version: 0.11.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: protocol-http2
85
85
  requirement: !ruby/object:Gem::Requirement