async-http 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/async/http/body.rb +105 -21
- data/lib/async/http/client.rb +1 -1
- data/lib/async/http/protocol/http11.rb +1 -47
- data/lib/async/http/protocol/http2.rb +3 -3
- data/lib/async/http/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87ea5fdd1668b7c17d499ee05a4d32a295560594c4d6a503c21efd9a3ea82a10
|
4
|
+
data.tar.gz: a1ad20020eecb10d1d295ba881c02c3cbefe82cb3a2e1d6453ce1cc082823535
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20966b6b196f4429295f9c765734ac52aa90709960fba46955e3769bcb360d820082f6d2555e1d5aa8b821f2f49630e47c592576c80fbc66faccf286915faef9
|
7
|
+
data.tar.gz: 2ed5fee97702faaf317adfca97c2bc5af6c2e1d21b17856fd8e66109cb7e831ba7f960ea809496038eacff1474b5d2694f7da579b87633dc5260f3d4dca3376e
|
data/lib/async/http/body.rb
CHANGED
@@ -26,24 +26,34 @@ module Async
|
|
26
26
|
def initialize
|
27
27
|
super
|
28
28
|
|
29
|
-
@
|
29
|
+
@finished = false
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
33
|
-
@
|
32
|
+
def finished?
|
33
|
+
@finished
|
34
34
|
end
|
35
35
|
|
36
36
|
def each
|
37
|
-
return if @
|
37
|
+
return if @finished
|
38
38
|
|
39
39
|
while chunk = self.dequeue
|
40
40
|
yield chunk
|
41
41
|
end
|
42
42
|
|
43
|
-
@
|
43
|
+
@finished = true
|
44
44
|
end
|
45
45
|
|
46
46
|
def read
|
47
|
+
return if @finished
|
48
|
+
|
49
|
+
unless chunk = self.dequeue
|
50
|
+
@finished = true
|
51
|
+
end
|
52
|
+
|
53
|
+
return chunk
|
54
|
+
end
|
55
|
+
|
56
|
+
def join
|
47
57
|
buffer = Async::IO::BinaryString.new
|
48
58
|
|
49
59
|
self.each do |chunk|
|
@@ -59,7 +69,7 @@ module Async
|
|
59
69
|
self.enqueue(chunk)
|
60
70
|
end
|
61
71
|
|
62
|
-
def
|
72
|
+
def finish
|
63
73
|
self.enqueue(nil)
|
64
74
|
end
|
65
75
|
end
|
@@ -67,6 +77,7 @@ module Async
|
|
67
77
|
class BufferedBody
|
68
78
|
def initialize(body)
|
69
79
|
@chunks = []
|
80
|
+
@index = 0
|
70
81
|
|
71
82
|
body.each do |chunk|
|
72
83
|
@chunks << chunk
|
@@ -74,26 +85,45 @@ module Async
|
|
74
85
|
end
|
75
86
|
|
76
87
|
def each(&block)
|
77
|
-
@chunks.
|
88
|
+
while @index < @chunks.count
|
89
|
+
yield @chunks[@index]
|
90
|
+
@index += 1
|
91
|
+
end
|
78
92
|
end
|
79
93
|
|
80
94
|
def read
|
81
|
-
|
95
|
+
if chunk = @chunks[@index]
|
96
|
+
@index += 1
|
97
|
+
end
|
98
|
+
|
99
|
+
return chunk
|
82
100
|
end
|
83
101
|
|
84
|
-
|
102
|
+
def join
|
103
|
+
buffer = Async::IO::BinaryString.new
|
104
|
+
|
105
|
+
self.each do |chunk|
|
106
|
+
buffer << chunk
|
107
|
+
end
|
108
|
+
|
109
|
+
return buffer
|
110
|
+
end
|
111
|
+
|
112
|
+
def rewind
|
113
|
+
@index = 0
|
114
|
+
end
|
85
115
|
|
86
|
-
def
|
116
|
+
def finished?
|
87
117
|
true
|
88
118
|
end
|
89
119
|
|
90
120
|
module Reader
|
91
121
|
def read
|
92
|
-
self.body ? self.body.
|
122
|
+
self.body ? self.body.join : nil
|
93
123
|
end
|
94
124
|
|
95
|
-
def
|
96
|
-
return if self.body.nil? or self.body.
|
125
|
+
def finish
|
126
|
+
return if self.body.nil? or self.body.finished?
|
97
127
|
|
98
128
|
unless self.body.is_a? BufferedBody
|
99
129
|
self.body = BufferedBody.new(self.body)
|
@@ -102,30 +132,84 @@ module Async
|
|
102
132
|
end
|
103
133
|
end
|
104
134
|
|
105
|
-
class
|
106
|
-
|
135
|
+
class ChunkedBody
|
136
|
+
def initialize(protocol)
|
137
|
+
@protocol = protocol
|
138
|
+
@finished = false
|
139
|
+
end
|
140
|
+
|
141
|
+
def finished?
|
142
|
+
@finished
|
143
|
+
end
|
107
144
|
|
145
|
+
def read
|
146
|
+
return nil if @finished
|
147
|
+
|
148
|
+
size = @protocol.read_line.to_i(16)
|
149
|
+
|
150
|
+
if size == 0
|
151
|
+
@protocol.read_line
|
152
|
+
|
153
|
+
@finished = true
|
154
|
+
|
155
|
+
return nil
|
156
|
+
end
|
157
|
+
|
158
|
+
chunk = @protocol.stream.read(size)
|
159
|
+
@protocol.read_line # Consume the trailing CRLF
|
160
|
+
|
161
|
+
return chunk
|
162
|
+
end
|
163
|
+
|
164
|
+
def each
|
165
|
+
while chunk = self.read
|
166
|
+
yield chunk
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def join
|
171
|
+
buffer = Async::IO::BinaryString.new
|
172
|
+
|
173
|
+
self.each do |chunk|
|
174
|
+
buffer << chunk
|
175
|
+
end
|
176
|
+
|
177
|
+
return buffer
|
178
|
+
end
|
179
|
+
|
180
|
+
def finish
|
181
|
+
self.each {}
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
class FixedBody
|
108
186
|
def initialize(length, stream)
|
109
187
|
@length = length
|
110
188
|
@remaining = length
|
111
189
|
@stream = stream
|
112
190
|
end
|
113
191
|
|
114
|
-
def
|
192
|
+
def finished?
|
115
193
|
@remaining == 0
|
116
194
|
end
|
117
195
|
|
118
196
|
def each
|
119
|
-
while
|
120
|
-
|
197
|
+
while chunk = self.read
|
198
|
+
yield chunk
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def read
|
203
|
+
if @remaining > 0
|
204
|
+
if chunk = @stream.read(@remaining)
|
121
205
|
@remaining -= chunk.bytesize
|
122
206
|
|
123
|
-
|
207
|
+
return chunk
|
124
208
|
end
|
125
209
|
end
|
126
210
|
end
|
127
211
|
|
128
|
-
def
|
212
|
+
def join
|
129
213
|
buffer = @stream.read(@remaining)
|
130
214
|
|
131
215
|
@remaining = 0
|
@@ -135,7 +219,7 @@ module Async
|
|
135
219
|
|
136
220
|
alias join read
|
137
221
|
|
138
|
-
def
|
222
|
+
def finish
|
139
223
|
read
|
140
224
|
end
|
141
225
|
end
|
data/lib/async/http/client.rb
CHANGED
@@ -72,7 +72,7 @@ module Async
|
|
72
72
|
|
73
73
|
write_response(request.version, status, headers, body)
|
74
74
|
|
75
|
-
request.
|
75
|
+
request.finish
|
76
76
|
|
77
77
|
unless keep_alive?(request.headers) and keep_alive?(headers)
|
78
78
|
@keep_alive = false
|
@@ -180,52 +180,6 @@ module Async
|
|
180
180
|
end
|
181
181
|
end
|
182
182
|
|
183
|
-
class ChunkedBody
|
184
|
-
def initialize(protocol)
|
185
|
-
@protocol = protocol
|
186
|
-
@closed = false
|
187
|
-
end
|
188
|
-
|
189
|
-
def closed?
|
190
|
-
@closed
|
191
|
-
end
|
192
|
-
|
193
|
-
def each
|
194
|
-
return if @closed
|
195
|
-
|
196
|
-
while true
|
197
|
-
size = @protocol.read_line.to_i(16)
|
198
|
-
|
199
|
-
if size == 0
|
200
|
-
@protocol.read_line
|
201
|
-
|
202
|
-
@closed = true
|
203
|
-
|
204
|
-
return
|
205
|
-
end
|
206
|
-
|
207
|
-
chunk = @protocol.stream.read(size)
|
208
|
-
@protocol.read_line # Consume the trailing CRLF
|
209
|
-
|
210
|
-
yield chunk
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
def read
|
215
|
-
buffer = Async::IO::BinaryString.new
|
216
|
-
|
217
|
-
self.each do |chunk|
|
218
|
-
buffer << chunk
|
219
|
-
end
|
220
|
-
|
221
|
-
return buffer
|
222
|
-
end
|
223
|
-
|
224
|
-
def close
|
225
|
-
self.each {}
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
183
|
def read_body(headers)
|
230
184
|
if headers['transfer-encoding'] == 'chunked'
|
231
185
|
return ChunkedBody.new(self)
|
@@ -127,7 +127,7 @@ module Async
|
|
127
127
|
stream.on(:half_close) do
|
128
128
|
response = yield request
|
129
129
|
|
130
|
-
request.body.
|
130
|
+
request.body.finish
|
131
131
|
|
132
132
|
# send response
|
133
133
|
headers = {STATUS => response[0].to_s}
|
@@ -202,8 +202,8 @@ module Async
|
|
202
202
|
|
203
203
|
stream.on(:close) do
|
204
204
|
Async.logger.debug(self) {"Stream closed, sending signal."}
|
205
|
-
# TODO should we prefer response.
|
206
|
-
response.body.
|
205
|
+
# TODO should we prefer `response.finish`?
|
206
|
+
response.body.finish
|
207
207
|
end
|
208
208
|
|
209
209
|
@stream.flush
|
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.15.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: 2018-04-
|
11
|
+
date: 2018-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|