biryani 0.0.2 → 0.0.4
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/biryani/connection.rb +77 -55
- data/lib/biryani/data_buffer.rb +1 -3
- data/lib/biryani/state.rb +3 -3
- data/lib/biryani/streams_context.rb +11 -16
- data/lib/biryani/utils.rb +15 -0
- data/lib/biryani/version.rb +1 -1
- data/lib/biryani/window.rb +8 -1
- data/spec/connection/handle_data_spec.rb +58 -0
- data/spec/connection/handle_headers_spec.rb +19 -0
- data/spec/connection/handle_rst_stream_spec.rb +4 -9
- data/spec/connection/handle_settings_spec.rb +3 -3
- data/spec/connection/handle_stream_window_update_spec.rb +5 -5
- data/spec/connection/send_spec.rb +12 -12
- data/spec/connection/transition_state_send_spec.rb +3 -3
- data/spec/data_buffer_spec.rb +15 -15
- data/spec/hpack/decoder_spec.rb +33 -33
- data/spec/hpack/encoder_spec.rb +10 -10
- data/spec/hpack/fields_spec.rb +3 -3
- data/spec/streams_context_spec.rb +15 -15
- data/spec/utils_spec.rb +41 -0
- metadata +7 -3
- data/spec/connection/unwrap_spec.rb +0 -28
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4ccf97951b31acac8912b7286f6377dedae6e404aab32e8c0eb619ef223d7349
|
|
4
|
+
data.tar.gz: 94563414ccb1a066ca85a9dc553541ea3772bc398e3d80a970e9f26b68d7f31b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c5e5cf9d6fc22cfe738483638b414bf0a82575030d9b4c0e400d5beab27da13b5b826390b563b972eca7fca8f5cbc44e8f693bf44abeab6eb360d9b09a91a3bd
|
|
7
|
+
data.tar.gz: f961a868e92ba46f300784f12568b0cd47cebc1cda484008b870480c22f63d5de66bf3d76fcddcbc96e192179c2d493a0fb1fbfc0b6cc189ba2852ee99af009a
|
data/lib/biryani/connection.rb
CHANGED
|
@@ -21,7 +21,7 @@ module Biryani
|
|
|
21
21
|
def initialize(proc)
|
|
22
22
|
@sock = nil # Ractor
|
|
23
23
|
@proc = proc
|
|
24
|
-
@streams_ctx = StreamsContext.new
|
|
24
|
+
@streams_ctx = StreamsContext.new(proc)
|
|
25
25
|
@encoder = HPACK::Encoder.new(4_096)
|
|
26
26
|
@decoder = HPACK::Decoder.new(4_096)
|
|
27
27
|
@send_window = Window.new(65_535)
|
|
@@ -77,7 +77,7 @@ module Biryani
|
|
|
77
77
|
port, obj = Ractor.select(*ports)
|
|
78
78
|
if port == @sock
|
|
79
79
|
if Biryani.err?(obj)
|
|
80
|
-
reply_frame =
|
|
80
|
+
reply_frame = Biryani.unwrap(obj, @streams_ctx.last_stream_id)
|
|
81
81
|
self.class.do_send(io, reply_frame, true)
|
|
82
82
|
close if self.class.transition_state_send(reply_frame, @streams_ctx)
|
|
83
83
|
elsif obj.length > @settings[SettingsID::SETTINGS_MAX_FRAME_SIZE]
|
|
@@ -85,8 +85,14 @@ module Biryani
|
|
|
85
85
|
close
|
|
86
86
|
else
|
|
87
87
|
recv_dispatch(obj).each do |frame|
|
|
88
|
-
reply_frame =
|
|
88
|
+
reply_frame = Biryani.unwrap(frame, @streams_ctx.last_stream_id)
|
|
89
89
|
self.class.do_send(io, reply_frame, true)
|
|
90
|
+
if reply_frame.f_type == FrameType::WINDOW_UPDATE && reply_frame.stream_id.zero?
|
|
91
|
+
@recv_window.increase!(reply_frame.window_size_increment)
|
|
92
|
+
elsif reply_frame.f_type == FrameType::WINDOW_UPDATE
|
|
93
|
+
@streams_ctx[reply_frame.stream_id].recv_window.increase!(reply_frame.window_size_increment)
|
|
94
|
+
end
|
|
95
|
+
|
|
90
96
|
close if self.class.transition_state_send(reply_frame, @streams_ctx)
|
|
91
97
|
end
|
|
92
98
|
end
|
|
@@ -96,14 +102,11 @@ module Biryani
|
|
|
96
102
|
max_frame_size = @peer_settings[SettingsID::SETTINGS_MAX_FRAME_SIZE]
|
|
97
103
|
self.class.send_headers(io, stream_id, fragment, data.empty?, max_frame_size, @streams_ctx)
|
|
98
104
|
self.class.send_data(io, stream_id, data, @send_window, max_frame_size, @streams_ctx, @data_buffer) unless data.empty?
|
|
99
|
-
|
|
100
|
-
@streams_ctx.remove_closed(@data_buffer)
|
|
101
105
|
end
|
|
102
106
|
|
|
107
|
+
@streams_ctx.remove_closed(@data_buffer)
|
|
103
108
|
break if closed?
|
|
104
109
|
end
|
|
105
|
-
ensure
|
|
106
|
-
@streams_ctx.clear_all
|
|
107
110
|
end
|
|
108
111
|
# rubocop: enable Metrics/AbcSize
|
|
109
112
|
# rubocop: enable Metrics/BlockLength
|
|
@@ -145,16 +148,17 @@ module Biryani
|
|
|
145
148
|
[ping_ack]
|
|
146
149
|
when FrameType::GOAWAY
|
|
147
150
|
self.class.handle_goaway(frame)
|
|
148
|
-
|
|
151
|
+
|
|
149
152
|
[]
|
|
150
153
|
when FrameType::WINDOW_UPDATE
|
|
151
154
|
err = self.class.handle_connection_window_update(frame, @send_window)
|
|
152
155
|
return [err] unless err.nil?
|
|
153
156
|
|
|
154
157
|
max_frame_size = @peer_settings[SettingsID::SETTINGS_MAX_FRAME_SIZE]
|
|
155
|
-
@data_buffer.take!(@send_window, @streams_ctx, max_frame_size)
|
|
158
|
+
@data_buffer.take!(@send_window, @streams_ctx, max_frame_size) # return DATA Frames
|
|
156
159
|
else
|
|
157
|
-
# ignore
|
|
160
|
+
# ignore UNKNOWN Frame
|
|
161
|
+
|
|
158
162
|
[]
|
|
159
163
|
end
|
|
160
164
|
end
|
|
@@ -166,7 +170,6 @@ module Biryani
|
|
|
166
170
|
# rubocop: disable Metrics/AbcSize
|
|
167
171
|
# rubocop: disable Metrics/CyclomaticComplexity
|
|
168
172
|
# rubocop: disable Metrics/MethodLength
|
|
169
|
-
# rubocop: disable Metrics/PerceivedComplexity
|
|
170
173
|
def handle_stream_frame(frame)
|
|
171
174
|
stream_id = frame.stream_id
|
|
172
175
|
typ = frame.f_type
|
|
@@ -176,40 +179,32 @@ module Biryani
|
|
|
176
179
|
max_streams = @peer_settings[SettingsID::SETTINGS_MAX_CONCURRENT_STREAMS]
|
|
177
180
|
send_initial_window_size = @peer_settings[SettingsID::SETTINGS_INITIAL_WINDOW_SIZE]
|
|
178
181
|
recv_initial_window_size = @settings[SettingsID::SETTINGS_INITIAL_WINDOW_SIZE]
|
|
179
|
-
obj = self.class.transition_state_recv(frame, @streams_ctx, stream_id, max_streams, send_initial_window_size, recv_initial_window_size
|
|
182
|
+
obj = self.class.transition_state_recv(frame, @streams_ctx, stream_id, max_streams, send_initial_window_size, recv_initial_window_size)
|
|
180
183
|
return [obj] if Biryani.err?(obj)
|
|
181
184
|
|
|
182
185
|
ctx = obj
|
|
183
186
|
case typ
|
|
184
187
|
when FrameType::DATA
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if ctx.state.half_closed_remote?
|
|
188
|
-
obj = self.class.http_request(ctx.fragment.string, ctx.content.string, @decoder)
|
|
189
|
-
return [obj] if Biryani.err?(obj)
|
|
190
|
-
|
|
191
|
-
ctx.stream.rx << obj
|
|
192
|
-
end
|
|
188
|
+
obj = self.class.handle_data(stream_id, frame.data, @recv_window, @streams_ctx, @decoder)
|
|
189
|
+
return [obj] if Biryani.err?(obj)
|
|
193
190
|
|
|
194
|
-
|
|
191
|
+
obj # return WINDOW_UPDATE Frames
|
|
195
192
|
when FrameType::HEADERS, FrameType::CONTINUATION
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
obj = self.class.http_request(ctx.fragment.string, ctx.content.string, @decoder)
|
|
199
|
-
return [obj] if Biryani.err?(obj)
|
|
200
|
-
|
|
201
|
-
ctx.stream.rx << obj
|
|
202
|
-
end
|
|
193
|
+
err = self.class.handle_headers(frame, ctx, @decoder)
|
|
194
|
+
return [err] unless err.nil?
|
|
203
195
|
|
|
204
196
|
[]
|
|
205
197
|
when FrameType::PRIORITY
|
|
206
198
|
# ignore PRIORITY Frame
|
|
199
|
+
|
|
207
200
|
[]
|
|
208
201
|
when FrameType::PUSH_PROMISE
|
|
209
202
|
# TODO
|
|
203
|
+
|
|
210
204
|
[]
|
|
211
205
|
when FrameType::RST_STREAM
|
|
212
|
-
self.class.handle_rst_stream(frame,
|
|
206
|
+
self.class.handle_rst_stream(frame, ctx)
|
|
207
|
+
|
|
213
208
|
[]
|
|
214
209
|
when FrameType::WINDOW_UPDATE
|
|
215
210
|
err = self.class.handle_stream_window_update(frame, @streams_ctx)
|
|
@@ -219,13 +214,13 @@ module Biryani
|
|
|
219
214
|
@data_buffer.take!(@send_window, @streams_ctx, max_frame_size)
|
|
220
215
|
else
|
|
221
216
|
# ignore UNKNOWN Frame
|
|
217
|
+
|
|
222
218
|
[]
|
|
223
219
|
end
|
|
224
220
|
end
|
|
225
221
|
# rubocop: enable Metrics/AbcSize
|
|
226
222
|
# rubocop: enable Metrics/CyclomaticComplexity
|
|
227
223
|
# rubocop: enable Metrics/MethodLength
|
|
228
|
-
# rubocop: enable Metrics/PerceivedComplexity
|
|
229
224
|
|
|
230
225
|
def close
|
|
231
226
|
@closed = true
|
|
@@ -236,39 +231,23 @@ module Biryani
|
|
|
236
231
|
@closed
|
|
237
232
|
end
|
|
238
233
|
|
|
239
|
-
# @param obj [Object, ConnectionError, StreamError] frame or error
|
|
240
|
-
# @param last_stream_id [Integer]
|
|
241
|
-
#
|
|
242
|
-
# @return [Frame]
|
|
243
|
-
def self.unwrap(obj, last_stream_id)
|
|
244
|
-
case obj
|
|
245
|
-
when ConnectionError
|
|
246
|
-
obj.goaway(last_stream_id)
|
|
247
|
-
when StreamError
|
|
248
|
-
obj.rst_stream
|
|
249
|
-
else
|
|
250
|
-
obj
|
|
251
|
-
end
|
|
252
|
-
end
|
|
253
|
-
|
|
254
234
|
# @param recv_frame [Object]
|
|
255
235
|
# @param streams_ctx [StreamsContext]
|
|
256
236
|
# @param stream_id [Integer]
|
|
257
237
|
# @param max_streams [Integer]
|
|
258
238
|
# @param send_initial_window_size [Integer]
|
|
259
239
|
# @param recv_initial_window_size [Integer]
|
|
260
|
-
# @param proc [Proc]
|
|
261
240
|
#
|
|
262
241
|
# @return [StreamContext, StreamError, ConnectionError]
|
|
263
242
|
# rubocop: disable Metrics/CyclomaticComplexity
|
|
264
243
|
# rubocop: disable Metrics/PerceivedComplexity
|
|
265
|
-
def self.transition_state_recv(recv_frame, streams_ctx, stream_id, max_streams, send_initial_window_size, recv_initial_window_size
|
|
244
|
+
def self.transition_state_recv(recv_frame, streams_ctx, stream_id, max_streams, send_initial_window_size, recv_initial_window_size)
|
|
266
245
|
ctx = streams_ctx[stream_id]
|
|
267
246
|
return StreamError.new(ErrorCode::PROTOCOL_ERROR, stream_id, 'exceed max concurrent streams') if ctx.nil? && streams_ctx.count_active + 1 > max_streams
|
|
268
247
|
return ConnectionError.new(ErrorCode::PROTOCOL_ERROR, 'even-numbered stream identifier') if ctx.nil? && stream_id.even?
|
|
269
248
|
return ConnectionError.new(ErrorCode::PROTOCOL_ERROR, 'new stream identifier is less than the existing stream identifiers') if ctx.nil? && streams_ctx.last_stream_id > stream_id
|
|
270
249
|
|
|
271
|
-
ctx = streams_ctx.new_context(stream_id, send_initial_window_size, recv_initial_window_size
|
|
250
|
+
ctx = streams_ctx.new_context(stream_id, send_initial_window_size, recv_initial_window_size) if ctx.nil?
|
|
272
251
|
obj = ctx.state.transition!(recv_frame, :recv)
|
|
273
252
|
return obj if Biryani.err?(obj)
|
|
274
253
|
|
|
@@ -291,7 +270,7 @@ module Biryani
|
|
|
291
270
|
streams_ctx.close_all
|
|
292
271
|
true
|
|
293
272
|
else
|
|
294
|
-
streams_ctx[stream_id].state.transition!(send_frame, :send)
|
|
273
|
+
streams_ctx[stream_id].state.transition!(send_frame, :send) unless stream_id.zero?
|
|
295
274
|
false
|
|
296
275
|
end
|
|
297
276
|
end
|
|
@@ -312,7 +291,7 @@ module Biryani
|
|
|
312
291
|
# @param streams_ctx [StreamsContext]
|
|
313
292
|
# @param data_buffer [DataBuffer]
|
|
314
293
|
def self.send_data(io, stream_id, data, send_window, max_frame_size, streams_ctx, data_buffer)
|
|
315
|
-
frames, remains = streams_ctx.
|
|
294
|
+
frames, remains = streams_ctx.sendable_datas(stream_id, data, send_window, max_frame_size)
|
|
316
295
|
|
|
317
296
|
frames.each do |frame|
|
|
318
297
|
do_send(io, frame, false)
|
|
@@ -355,11 +334,55 @@ module Biryani
|
|
|
355
334
|
ConnectionError.new(ErrorCode::PROTOCOL_ERROR, 'invalid connection preface') if s != CONNECTION_PREFACE
|
|
356
335
|
end
|
|
357
336
|
|
|
358
|
-
# @param
|
|
337
|
+
# @param stream_id [Integer]
|
|
338
|
+
# @param data [String]
|
|
339
|
+
# @param recv_window [Window]
|
|
359
340
|
# @param streams_ctx [StreamsContext]
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
341
|
+
# @param decoder [Decoder]
|
|
342
|
+
#
|
|
343
|
+
# @return [Array<WindowUpdate>, ConnectionError]
|
|
344
|
+
# rubocop: disable Metrics/AbcSize
|
|
345
|
+
def self.handle_data(stream_id, data, recv_window, streams_ctx, decoder)
|
|
346
|
+
ctx = streams_ctx[stream_id]
|
|
347
|
+
return ConnectionError.new(ErrorCode::FLOW_CONTROL_ERROR, 'DATA Frame length exceeds flow-control window size') \
|
|
348
|
+
if recv_window.consume!(data.bytesize).negative? || ctx.recv_window.consume!(data.bytesize).negative?
|
|
349
|
+
|
|
350
|
+
ctx.content << data
|
|
351
|
+
if ctx.half_closed_remote?
|
|
352
|
+
obj = http_request(ctx.fragment.string, ctx.content.string, decoder)
|
|
353
|
+
return obj if Biryani.err?(obj)
|
|
354
|
+
|
|
355
|
+
ctx.stream.rx << obj
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
window_updates = []
|
|
359
|
+
window_updates << Frame::WindowUpdate.new(0, recv_window.capacity - recv_window.length) if recv_window.length < recv_window.capacity / 2
|
|
360
|
+
window_updates << Frame::WindowUpdate.new(stream_id, ctx.recv_window.capacity - ctx.recv_window.length) if ctx.recv_window.length < ctx.recv_window.capacity / 2
|
|
361
|
+
window_updates
|
|
362
|
+
end
|
|
363
|
+
# rubocop: enable Metrics/AbcSize
|
|
364
|
+
|
|
365
|
+
# @param headers [Headers]
|
|
366
|
+
# @param ctx [StreamContext]
|
|
367
|
+
# @param decoder [Decoder]
|
|
368
|
+
#
|
|
369
|
+
# @return [nil, ConnectionError]
|
|
370
|
+
def self.handle_headers(headers, ctx, decoder)
|
|
371
|
+
ctx.fragment << headers.fragment
|
|
372
|
+
if ctx.half_closed_remote?
|
|
373
|
+
obj = http_request(ctx.fragment.string, ctx.content.string, decoder)
|
|
374
|
+
return [obj] if Biryani.err?(obj)
|
|
375
|
+
|
|
376
|
+
ctx.stream.rx << obj
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
nil
|
|
380
|
+
end
|
|
381
|
+
|
|
382
|
+
# @param _rst_stream [RstStream]
|
|
383
|
+
# @param ctx [StreamContext]
|
|
384
|
+
def self.handle_rst_stream(_rst_stream, ctx)
|
|
385
|
+
ctx.state.close
|
|
363
386
|
end
|
|
364
387
|
|
|
365
388
|
# @param settings [Settings]
|
|
@@ -397,7 +420,6 @@ module Biryani
|
|
|
397
420
|
#
|
|
398
421
|
# @return [nil, ConnectionError]
|
|
399
422
|
def self.handle_connection_window_update(window_update, send_window)
|
|
400
|
-
# TODO: send WINDOW_UPDATE to do the flow-conrol
|
|
401
423
|
send_window.increase!(window_update.window_size_increment)
|
|
402
424
|
return ConnectionError.new(ErrorCode::FLOW_CONTROL_ERROR, 'flow-control window exceeds 2^31-1') if send_window.length > 2**31 - 1
|
|
403
425
|
|
data/lib/biryani/data_buffer.rb
CHANGED
|
@@ -19,9 +19,7 @@ module Biryani
|
|
|
19
19
|
def take!(send_window, streams_ctx, max_frame_size)
|
|
20
20
|
datas = []
|
|
21
21
|
@buffer.each do |stream_id, data|
|
|
22
|
-
frames, remains = streams_ctx.
|
|
23
|
-
next if frames.empty?
|
|
24
|
-
|
|
22
|
+
frames, remains = streams_ctx.sendable_datas(stream_id, data, send_window, max_frame_size)
|
|
25
23
|
datas += frames
|
|
26
24
|
if remains.empty?
|
|
27
25
|
@buffer.delete(stream_id)
|
data/lib/biryani/state.rb
CHANGED
|
@@ -100,12 +100,12 @@ module Biryani
|
|
|
100
100
|
# receiving_data
|
|
101
101
|
in [:receiving_data, FrameType::DATA, :recv] if frame.end_stream?
|
|
102
102
|
:half_closed_remote
|
|
103
|
-
in [:receiving_data, FrameType::WINDOW_UPDATE, :recv]
|
|
104
|
-
state
|
|
105
103
|
in [:receiving_data, FrameType::DATA, :recv]
|
|
106
104
|
state
|
|
107
105
|
in [:receiving_data, FrameType::RST_STREAM, _]
|
|
108
106
|
:closed
|
|
107
|
+
in [:receiving_data, FrameType::WINDOW_UPDATE, _]
|
|
108
|
+
state
|
|
109
109
|
in [:receiving_data, _, _]
|
|
110
110
|
unexpected(ErrorCode::PROTOCOL_ERROR, state, typ, direction)
|
|
111
111
|
|
|
@@ -132,7 +132,7 @@ module Biryani
|
|
|
132
132
|
state
|
|
133
133
|
in [:half_closed_remote, FrameType::RST_STREAM, _]
|
|
134
134
|
:closed
|
|
135
|
-
in [half_closed_remote, FrameType::WINDOW_UPDATE,
|
|
135
|
+
in [:half_closed_remote, FrameType::WINDOW_UPDATE, _]
|
|
136
136
|
state
|
|
137
137
|
in [:half_closed_remote, _, :recv]
|
|
138
138
|
unexpected(ErrorCode::STREAM_CLOSED, state, typ, direction)
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
module Biryani
|
|
2
2
|
class StreamsContext
|
|
3
|
-
def initialize
|
|
4
|
-
@h = {}
|
|
3
|
+
def initialize(proc)
|
|
4
|
+
@h = {} # Hash<Integer, StreamContext>
|
|
5
|
+
@proc = proc
|
|
5
6
|
end
|
|
6
7
|
|
|
7
8
|
# @param stream_id [Integer]
|
|
8
9
|
# @param send_initial_window_size [Integer]
|
|
9
10
|
# @param recv_initial_window_size [Integer]
|
|
10
|
-
# @param proc [Proc]
|
|
11
11
|
#
|
|
12
12
|
# @return [StreamContext]
|
|
13
|
-
def new_context(stream_id, send_initial_window_size, recv_initial_window_size
|
|
14
|
-
ctx = StreamContext.new(stream_id, send_initial_window_size, recv_initial_window_size, proc)
|
|
13
|
+
def new_context(stream_id, send_initial_window_size, recv_initial_window_size)
|
|
14
|
+
ctx = StreamContext.new(stream_id, send_initial_window_size, recv_initial_window_size, @proc)
|
|
15
15
|
@h[stream_id] = ctx
|
|
16
16
|
ctx
|
|
17
17
|
end
|
|
@@ -64,7 +64,7 @@ module Biryani
|
|
|
64
64
|
#
|
|
65
65
|
# @return [Array<Object>] frames
|
|
66
66
|
# @return [String]
|
|
67
|
-
def
|
|
67
|
+
def sendable_datas(stream_id, data, send_window, max_frame_size)
|
|
68
68
|
len = [data.bytesize, send_window.length, @h[stream_id].send_window.length].min
|
|
69
69
|
|
|
70
70
|
payload = data[0...len]
|
|
@@ -84,7 +84,6 @@ module Biryani
|
|
|
84
84
|
closed_ids = closed_stream_ids.filter { |id| !data_buffer.has?(id) }
|
|
85
85
|
closed_ids.each do |id|
|
|
86
86
|
@h[id].tx.close
|
|
87
|
-
@h[id].stream.rx << nil
|
|
88
87
|
@h[id].fragment.close
|
|
89
88
|
@h[id].content.close
|
|
90
89
|
end
|
|
@@ -98,15 +97,6 @@ module Biryani
|
|
|
98
97
|
ctx.state.close
|
|
99
98
|
end
|
|
100
99
|
end
|
|
101
|
-
|
|
102
|
-
def clear_all
|
|
103
|
-
each do |ctx|
|
|
104
|
-
ctx.tx.close
|
|
105
|
-
ctx.stream.rx << nil
|
|
106
|
-
ctx.fragment.close
|
|
107
|
-
ctx.content.close
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
100
|
end
|
|
111
101
|
|
|
112
102
|
class StreamContext
|
|
@@ -140,5 +130,10 @@ module Biryani
|
|
|
140
130
|
def active?
|
|
141
131
|
@state.active?
|
|
142
132
|
end
|
|
133
|
+
|
|
134
|
+
# @return [Boolean]
|
|
135
|
+
def half_closed_remote?
|
|
136
|
+
@state.half_closed_remote?
|
|
137
|
+
end
|
|
143
138
|
end
|
|
144
139
|
end
|
data/lib/biryani/utils.rb
CHANGED
|
@@ -5,4 +5,19 @@ module Biryani
|
|
|
5
5
|
def self.err?(obj)
|
|
6
6
|
obj.is_a?(StreamError) || obj.is_a?(ConnectionError)
|
|
7
7
|
end
|
|
8
|
+
|
|
9
|
+
# @param obj [Object, ConnectionError, StreamError] frame or error
|
|
10
|
+
# @param last_stream_id [Integer]
|
|
11
|
+
#
|
|
12
|
+
# @return [Frame]
|
|
13
|
+
def self.unwrap(obj, last_stream_id)
|
|
14
|
+
case obj
|
|
15
|
+
when ConnectionError
|
|
16
|
+
obj.goaway(last_stream_id)
|
|
17
|
+
when StreamError
|
|
18
|
+
obj.rst_stream
|
|
19
|
+
else
|
|
20
|
+
obj
|
|
21
|
+
end
|
|
22
|
+
end
|
|
8
23
|
end
|
data/lib/biryani/version.rb
CHANGED
data/lib/biryani/window.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module Biryani
|
|
2
2
|
class Window
|
|
3
|
-
attr_reader :length
|
|
3
|
+
attr_reader :length, :capacity
|
|
4
4
|
|
|
5
5
|
# @param initial_window_size [Integer]
|
|
6
6
|
def initialize(initial_window_size)
|
|
@@ -9,19 +9,26 @@ module Biryani
|
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
# @param length [Integer]
|
|
12
|
+
#
|
|
13
|
+
# @return [Integer]
|
|
12
14
|
def consume!(length)
|
|
13
15
|
@length -= length
|
|
14
16
|
end
|
|
15
17
|
|
|
16
18
|
# @param length [Integer]
|
|
19
|
+
#
|
|
20
|
+
# @return [Integer]
|
|
17
21
|
def increase!(length)
|
|
18
22
|
@length += length
|
|
19
23
|
end
|
|
20
24
|
|
|
21
25
|
# @param initial_window_size [Integer]
|
|
26
|
+
#
|
|
27
|
+
# @return [Integer]
|
|
22
28
|
def update!(initial_window_size)
|
|
23
29
|
@length = initial_window_size - @capacity + @length
|
|
24
30
|
@capacity = initial_window_size
|
|
31
|
+
@length
|
|
25
32
|
end
|
|
26
33
|
end
|
|
27
34
|
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require_relative '../spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe Connection do
|
|
4
|
+
context 'handle_data' do
|
|
5
|
+
let(:decoder) do
|
|
6
|
+
HPACK::Decoder.new(4_096)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
let(:recv_window1) do
|
|
10
|
+
Window.new(65_535)
|
|
11
|
+
end
|
|
12
|
+
let(:streams_ctx1) do
|
|
13
|
+
streams_ctx = StreamsContext.new(do_nothing_proc)
|
|
14
|
+
streams_ctx.new_context(1, 65_535, 65_535)
|
|
15
|
+
streams_ctx.new_context(2, 65_535, 65_535)
|
|
16
|
+
streams_ctx
|
|
17
|
+
end
|
|
18
|
+
it 'should handle' do
|
|
19
|
+
expect(Connection.handle_data(2, 'Hello, world!', recv_window1, streams_ctx1, decoder)).to eq []
|
|
20
|
+
expect(streams_ctx1[2].content.string).to eq 'Hello, world!'
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
let(:recv_window2) do
|
|
24
|
+
recv_window = Window.new(65_535)
|
|
25
|
+
recv_window.consume!(65_535 / 2)
|
|
26
|
+
recv_window
|
|
27
|
+
end
|
|
28
|
+
let(:streams_ctx2) do
|
|
29
|
+
streams_ctx = StreamsContext.new(do_nothing_proc)
|
|
30
|
+
streams_ctx.new_context(1, 65_535, 65_535)
|
|
31
|
+
streams_ctx.new_context(2, 65_535, 65_535)
|
|
32
|
+
streams_ctx[2].recv_window.consume!(65_535 / 2)
|
|
33
|
+
streams_ctx
|
|
34
|
+
end
|
|
35
|
+
it 'should handle' do
|
|
36
|
+
frames = Connection.handle_data(2, 'Hello, world!', recv_window2, streams_ctx2, decoder)
|
|
37
|
+
expect(frames.map(&:f_type)).to eq [FrameType::WINDOW_UPDATE, FrameType::WINDOW_UPDATE]
|
|
38
|
+
expect(frames.map(&:stream_id)).to eq [0, 2]
|
|
39
|
+
expect(frames.map(&:window_size_increment)).to eq [65_535 / 2 + 13, 65_535 / 2 + 13]
|
|
40
|
+
expect(streams_ctx2[2].content.string).to eq 'Hello, world!'
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
let(:recv_window3) do
|
|
44
|
+
recv_window = Window.new(65_535)
|
|
45
|
+
recv_window.consume!(65_535)
|
|
46
|
+
recv_window
|
|
47
|
+
end
|
|
48
|
+
let(:streams_ctx3) do
|
|
49
|
+
streams_ctx = StreamsContext.new(do_nothing_proc)
|
|
50
|
+
streams_ctx.new_context(1, 65_535, 65_535)
|
|
51
|
+
streams_ctx.new_context(2, 65_535, 65_535)
|
|
52
|
+
streams_ctx
|
|
53
|
+
end
|
|
54
|
+
it 'should not handle' do
|
|
55
|
+
expect(Connection.handle_data(2, 'Hello, world!', recv_window3, streams_ctx3, decoder)).to be_kind_of ConnectionError
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require_relative '../spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe Connection do
|
|
4
|
+
context 'handle_headers' do
|
|
5
|
+
let(:headers) do
|
|
6
|
+
Frame::Headers.new(true, false, 2, nil, nil, 'this is dummy', nil)
|
|
7
|
+
end
|
|
8
|
+
let(:ctx) do
|
|
9
|
+
StreamContext.new(2, 65_535, 65_535, do_nothing_proc)
|
|
10
|
+
end
|
|
11
|
+
let(:decoder) do
|
|
12
|
+
HPACK::Decoder.new(4_096)
|
|
13
|
+
end
|
|
14
|
+
it 'should handle' do
|
|
15
|
+
expect(Connection.handle_headers(headers, ctx, decoder)).to eq nil
|
|
16
|
+
expect(ctx.fragment.string).to eq 'this is dummy'
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -5,17 +5,12 @@ RSpec.describe Connection do
|
|
|
5
5
|
let(:rst_stream) do
|
|
6
6
|
Frame::RstStream.new(2, 0)
|
|
7
7
|
end
|
|
8
|
-
let(:
|
|
9
|
-
|
|
10
|
-
streams_ctx.new_context(1, 65_535, 65_535, do_nothing_proc)
|
|
11
|
-
streams_ctx.new_context(2, 65_535, 65_535, do_nothing_proc)
|
|
12
|
-
streams_ctx
|
|
8
|
+
let(:ctx) do
|
|
9
|
+
StreamContext.new(2, 65_535, 65_535, do_nothing_proc)
|
|
13
10
|
end
|
|
14
11
|
it 'should handle' do
|
|
15
|
-
Connection.handle_rst_stream(rst_stream,
|
|
16
|
-
expect(
|
|
17
|
-
expect(streams_ctx.count_active).to eq 0
|
|
18
|
-
expect(streams_ctx.closed_stream_ids.length).to eq 1
|
|
12
|
+
Connection.handle_rst_stream(rst_stream, ctx)
|
|
13
|
+
expect(ctx.closed?).to eq true
|
|
19
14
|
end
|
|
20
15
|
end
|
|
21
16
|
end
|
|
@@ -9,9 +9,9 @@ RSpec.describe Connection do
|
|
|
9
9
|
HPACK::Decoder.new(4_096)
|
|
10
10
|
end
|
|
11
11
|
let(:streams_ctx) do
|
|
12
|
-
streams_ctx = StreamsContext.new
|
|
13
|
-
streams_ctx.new_context(1, 65_535, 65_535
|
|
14
|
-
streams_ctx.new_context(2, 65_535, 65_535
|
|
12
|
+
streams_ctx = StreamsContext.new(do_nothing_proc)
|
|
13
|
+
streams_ctx.new_context(1, 65_535, 65_535)
|
|
14
|
+
streams_ctx.new_context(2, 65_535, 65_535)
|
|
15
15
|
streams_ctx
|
|
16
16
|
end
|
|
17
17
|
|
|
@@ -6,15 +6,15 @@ RSpec.describe Connection do
|
|
|
6
6
|
Frame::WindowUpdate.new(1, 1000)
|
|
7
7
|
end
|
|
8
8
|
let(:streams_ctx) do
|
|
9
|
-
streams_ctx = StreamsContext.new
|
|
10
|
-
streams_ctx.new_context(1, 65_535, 65_535
|
|
11
|
-
streams_ctx.new_context(2, 65_535, 65_535
|
|
9
|
+
streams_ctx = StreamsContext.new(do_nothing_proc)
|
|
10
|
+
streams_ctx.new_context(1, 65_535, 65_535)
|
|
11
|
+
streams_ctx.new_context(2, 65_535, 65_535)
|
|
12
12
|
streams_ctx
|
|
13
13
|
end
|
|
14
14
|
it 'should handle' do
|
|
15
15
|
expect { Connection.handle_stream_window_update(window_update, streams_ctx) }.not_to raise_error
|
|
16
|
-
expect(streams_ctx[1].send_window.length).to eq
|
|
17
|
-
expect(streams_ctx[2].send_window.length).to eq
|
|
16
|
+
expect(streams_ctx[1].send_window.length).to eq 65_535 + 1000
|
|
17
|
+
expect(streams_ctx[2].send_window.length).to eq 65_535
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
end
|
|
@@ -16,9 +16,9 @@ RSpec.describe Connection do
|
|
|
16
16
|
Window.new(65_535)
|
|
17
17
|
end
|
|
18
18
|
let(:streams_ctx1) do
|
|
19
|
-
streams_ctx = StreamsContext.new
|
|
20
|
-
streams_ctx.new_context(1, 65_535, 65_535
|
|
21
|
-
streams_ctx.new_context(2, 65_535, 65_535
|
|
19
|
+
streams_ctx = StreamsContext.new(do_nothing_proc)
|
|
20
|
+
streams_ctx.new_context(1, 65_535, 65_535)
|
|
21
|
+
streams_ctx.new_context(2, 65_535, 65_535)
|
|
22
22
|
streams_ctx
|
|
23
23
|
end
|
|
24
24
|
it 'should send' do
|
|
@@ -39,9 +39,9 @@ RSpec.describe Connection do
|
|
|
39
39
|
Window.new(65_535)
|
|
40
40
|
end
|
|
41
41
|
let(:streams_ctx2) do
|
|
42
|
-
streams_ctx = StreamsContext.new
|
|
43
|
-
streams_ctx.new_context(1, 65_535, 65_535
|
|
44
|
-
streams_ctx.new_context(2, 65_535, 65_535
|
|
42
|
+
streams_ctx = StreamsContext.new(do_nothing_proc)
|
|
43
|
+
streams_ctx.new_context(1, 65_535, 65_535)
|
|
44
|
+
streams_ctx.new_context(2, 65_535, 65_535)
|
|
45
45
|
streams_ctx
|
|
46
46
|
end
|
|
47
47
|
it 'should send' do
|
|
@@ -61,9 +61,9 @@ RSpec.describe Connection do
|
|
|
61
61
|
Window.new(65_535)
|
|
62
62
|
end
|
|
63
63
|
let(:streams_ctx3) do
|
|
64
|
-
streams_ctx = StreamsContext.new
|
|
65
|
-
streams_ctx.new_context(1, 65_535, 65_535
|
|
66
|
-
streams_ctx.new_context(2, 65_535, 65_535
|
|
64
|
+
streams_ctx = StreamsContext.new(do_nothing_proc)
|
|
65
|
+
streams_ctx.new_context(1, 65_535, 65_535)
|
|
66
|
+
streams_ctx.new_context(2, 65_535, 65_535)
|
|
67
67
|
streams_ctx[2].send_window.consume!(65_535)
|
|
68
68
|
streams_ctx
|
|
69
69
|
end
|
|
@@ -86,9 +86,9 @@ RSpec.describe Connection do
|
|
|
86
86
|
send_window
|
|
87
87
|
end
|
|
88
88
|
let(:streams_ctx4) do
|
|
89
|
-
streams_ctx = StreamsContext.new
|
|
90
|
-
streams_ctx.new_context(1, 65_535, 65_535
|
|
91
|
-
streams_ctx.new_context(2, 65_535, 65_535
|
|
89
|
+
streams_ctx = StreamsContext.new(do_nothing_proc)
|
|
90
|
+
streams_ctx.new_context(1, 65_535, 65_535)
|
|
91
|
+
streams_ctx.new_context(2, 65_535, 65_535)
|
|
92
92
|
streams_ctx
|
|
93
93
|
end
|
|
94
94
|
it 'should send' do
|
|
@@ -3,9 +3,9 @@ require_relative '../spec_helper'
|
|
|
3
3
|
RSpec.describe Connection do
|
|
4
4
|
context 'transition_state_send' do
|
|
5
5
|
let(:streams_ctx) do
|
|
6
|
-
streams_ctx = StreamsContext.new
|
|
7
|
-
streams_ctx.new_context(1, 65_535, 65_535
|
|
8
|
-
streams_ctx.new_context(2, 65_535, 65_535
|
|
6
|
+
streams_ctx = StreamsContext.new(do_nothing_proc)
|
|
7
|
+
streams_ctx.new_context(1, 65_535, 65_535)
|
|
8
|
+
streams_ctx.new_context(2, 65_535, 65_535)
|
|
9
9
|
streams_ctx
|
|
10
10
|
end
|
|
11
11
|
|
data/spec/data_buffer_spec.rb
CHANGED
|
@@ -9,9 +9,9 @@ RSpec.describe DataBuffer do
|
|
|
9
9
|
Window.new(65_535)
|
|
10
10
|
end
|
|
11
11
|
let(:streams_ctx1) do
|
|
12
|
-
streams_ctx = StreamsContext.new
|
|
13
|
-
streams_ctx.new_context(1, 65_535, 65_535
|
|
14
|
-
streams_ctx.new_context(2, 65_535, 65_535
|
|
12
|
+
streams_ctx = StreamsContext.new(do_nothing_proc)
|
|
13
|
+
streams_ctx.new_context(1, 65_535, 65_535)
|
|
14
|
+
streams_ctx.new_context(2, 65_535, 65_535)
|
|
15
15
|
streams_ctx
|
|
16
16
|
end
|
|
17
17
|
it 'should take' do
|
|
@@ -31,9 +31,9 @@ RSpec.describe DataBuffer do
|
|
|
31
31
|
Window.new(65_535)
|
|
32
32
|
end
|
|
33
33
|
let(:streams_ctx2) do
|
|
34
|
-
streams_ctx = StreamsContext.new
|
|
35
|
-
streams_ctx.new_context(1, 65_535, 65_535
|
|
36
|
-
streams_ctx.new_context(2, 65_535, 65_535
|
|
34
|
+
streams_ctx = StreamsContext.new(do_nothing_proc)
|
|
35
|
+
streams_ctx.new_context(1, 65_535, 65_535)
|
|
36
|
+
streams_ctx.new_context(2, 65_535, 65_535)
|
|
37
37
|
streams_ctx
|
|
38
38
|
end
|
|
39
39
|
it 'should take' do
|
|
@@ -55,9 +55,9 @@ RSpec.describe DataBuffer do
|
|
|
55
55
|
Window.new(65_535)
|
|
56
56
|
end
|
|
57
57
|
let(:streams_ctx3) do
|
|
58
|
-
streams_ctx = StreamsContext.new
|
|
59
|
-
streams_ctx.new_context(1, 65_535, 65_535
|
|
60
|
-
streams_ctx.new_context(2, 65_535, 65_535
|
|
58
|
+
streams_ctx = StreamsContext.new(do_nothing_proc)
|
|
59
|
+
streams_ctx.new_context(1, 65_535, 65_535)
|
|
60
|
+
streams_ctx.new_context(2, 65_535, 65_535)
|
|
61
61
|
streams_ctx
|
|
62
62
|
end
|
|
63
63
|
it 'should take' do
|
|
@@ -80,10 +80,10 @@ RSpec.describe DataBuffer do
|
|
|
80
80
|
Window.new(65_535)
|
|
81
81
|
end
|
|
82
82
|
let(:streams_ctx4) do
|
|
83
|
-
streams_ctx = StreamsContext.new
|
|
84
|
-
streams_ctx.new_context(1, 65_535, 65_535
|
|
83
|
+
streams_ctx = StreamsContext.new(do_nothing_proc)
|
|
84
|
+
streams_ctx.new_context(1, 65_535, 65_535)
|
|
85
85
|
streams_ctx[1].send_window.consume!(65_535)
|
|
86
|
-
streams_ctx.new_context(2, 65_535, 65_535
|
|
86
|
+
streams_ctx.new_context(2, 65_535, 65_535)
|
|
87
87
|
streams_ctx
|
|
88
88
|
end
|
|
89
89
|
it 'should take' do
|
|
@@ -108,9 +108,9 @@ RSpec.describe DataBuffer do
|
|
|
108
108
|
send_window
|
|
109
109
|
end
|
|
110
110
|
let(:streams_ctx5) do
|
|
111
|
-
streams_ctx = StreamsContext.new
|
|
112
|
-
streams_ctx.new_context(1, 65_535, 65_535
|
|
113
|
-
streams_ctx.new_context(2, 65_535, 65_535
|
|
111
|
+
streams_ctx = StreamsContext.new(do_nothing_proc)
|
|
112
|
+
streams_ctx.new_context(1, 65_535, 65_535)
|
|
113
|
+
streams_ctx.new_context(2, 65_535, 65_535)
|
|
114
114
|
streams_ctx
|
|
115
115
|
end
|
|
116
116
|
it 'should take' do
|
data/spec/hpack/decoder_spec.rb
CHANGED
|
@@ -9,8 +9,8 @@ RSpec.describe HPACK::Decoder do
|
|
|
9
9
|
it 'should decode' do
|
|
10
10
|
# https://datatracker.ietf.org/doc/html/rfc7541#appendix-C.3.1
|
|
11
11
|
expect(decoder.decode([<<HEXDUMP.split.join].pack('H*')
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
8286 8441 0f77 7777 2e65 7861 6d70 6c65
|
|
13
|
+
2e63 6f6d
|
|
14
14
|
HEXDUMP
|
|
15
15
|
)).to eq [
|
|
16
16
|
[':method', 'GET'],
|
|
@@ -20,7 +20,7 @@ HEXDUMP
|
|
|
20
20
|
]
|
|
21
21
|
# https://datatracker.ietf.org/doc/html/rfc7541#appendix-C.3.2
|
|
22
22
|
expect(decoder.decode([<<HEXDUMP.split.join].pack('H*')
|
|
23
|
-
|
|
23
|
+
8286 84be 5808 6e6f 2d63 6163 6865
|
|
24
24
|
HEXDUMP
|
|
25
25
|
)).to eq [
|
|
26
26
|
[':method', 'GET'],
|
|
@@ -31,8 +31,8 @@ HEXDUMP
|
|
|
31
31
|
]
|
|
32
32
|
# https://datatracker.ietf.org/doc/html/rfc7541#appendix-C.3.3
|
|
33
33
|
expect(decoder.decode([<<HEXDUMP.split.join].pack('H*')
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
8287 85bf 400a 6375 7374 6f6d 2d6b 6579
|
|
35
|
+
0c63 7573 746f 6d2d 7661 6c75 65
|
|
36
36
|
HEXDUMP
|
|
37
37
|
)).to eq [
|
|
38
38
|
[':method', 'GET'],
|
|
@@ -46,8 +46,8 @@ HEXDUMP
|
|
|
46
46
|
it 'should decode' do
|
|
47
47
|
# https://datatracker.ietf.org/doc/html/rfc7541#appendix-C.4.1
|
|
48
48
|
expect(decoder.decode([<<HEXDUMP.split.join].pack('H*')
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
8286 8441 8cf1 e3c2 e5f2 3a6b a0ab 90f4
|
|
50
|
+
ff
|
|
51
51
|
HEXDUMP
|
|
52
52
|
)).to eq [
|
|
53
53
|
[':method', 'GET'],
|
|
@@ -57,7 +57,7 @@ HEXDUMP
|
|
|
57
57
|
]
|
|
58
58
|
# https://datatracker.ietf.org/doc/html/rfc7541#appendix-C.4.2
|
|
59
59
|
expect(decoder.decode([<<HEXDUMP.split.join].pack('H*')
|
|
60
|
-
|
|
60
|
+
8286 84be 5886 a8eb 1064 9cbf
|
|
61
61
|
HEXDUMP
|
|
62
62
|
)).to eq [
|
|
63
63
|
[':method', 'GET'],
|
|
@@ -68,8 +68,8 @@ HEXDUMP
|
|
|
68
68
|
]
|
|
69
69
|
# https://datatracker.ietf.org/doc/html/rfc7541#appendix-C.4.3
|
|
70
70
|
expect(decoder.decode([<<HEXDUMP.split.join].pack('H*')
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
8287 85bf 4088 25a8 49e9 5ba9 7d7f 8925
|
|
72
|
+
a849 e95b b8e8 b4bf
|
|
73
73
|
HEXDUMP
|
|
74
74
|
)).to eq [
|
|
75
75
|
[':method', 'GET'],
|
|
@@ -83,11 +83,11 @@ HEXDUMP
|
|
|
83
83
|
it 'should decode' do
|
|
84
84
|
# https://datatracker.ietf.org/doc/html/rfc7541#appendix-C.5.1
|
|
85
85
|
expect(decoder.decode([<<HEXDUMP.split.join].pack('H*')
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
4803 3330 3258 0770 7269 7661 7465 611d
|
|
87
|
+
4d6f 6e2c 2032 3120 4f63 7420 3230 3133
|
|
88
|
+
2032 303a 3133 3a32 3120 474d 546e 1768
|
|
89
|
+
7474 7073 3a2f 2f77 7777 2e65 7861 6d70
|
|
90
|
+
6c65 2e63 6f6d
|
|
91
91
|
HEXDUMP
|
|
92
92
|
)).to eq [
|
|
93
93
|
[':status', '302'],
|
|
@@ -97,7 +97,7 @@ HEXDUMP
|
|
|
97
97
|
]
|
|
98
98
|
# https://datatracker.ietf.org/doc/html/rfc7541#appendix-C.5.2
|
|
99
99
|
expect(decoder.decode([<<HEXDUMP.split.join].pack('H*')
|
|
100
|
-
|
|
100
|
+
4803 3330 37c1 c0bf
|
|
101
101
|
HEXDUMP
|
|
102
102
|
)).to eq [
|
|
103
103
|
[':status', '307'],
|
|
@@ -107,13 +107,13 @@ HEXDUMP
|
|
|
107
107
|
]
|
|
108
108
|
# https://datatracker.ietf.org/doc/html/rfc7541#appendix-C.5.3
|
|
109
109
|
expect(decoder.decode([<<HEXDUMP.split.join].pack('H*')
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
110
|
+
88c1 611d 4d6f 6e2c 2032 3120 4f63 7420
|
|
111
|
+
3230 3133 2032 303a 3133 3a32 3220 474d
|
|
112
|
+
54c0 5a04 677a 6970 7738 666f 6f3d 4153
|
|
113
|
+
444a 4b48 514b 425a 584f 5157 454f 5049
|
|
114
|
+
5541 5851 5745 4f49 553b 206d 6178 2d61
|
|
115
|
+
6765 3d33 3630 303b 2076 6572 7369 6f6e
|
|
116
|
+
3d31
|
|
117
117
|
HEXDUMP
|
|
118
118
|
)).to eq [
|
|
119
119
|
[':status', '200'],
|
|
@@ -128,10 +128,10 @@ HEXDUMP
|
|
|
128
128
|
it 'should decode' do
|
|
129
129
|
# https://datatracker.ietf.org/doc/html/rfc7541#appendix-C.6.1
|
|
130
130
|
expect(decoder.decode([<<HEXDUMP.split.join].pack('H*')
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
131
|
+
4882 6402 5885 aec3 771a 4b61 96d0 7abe
|
|
132
|
+
9410 54d4 44a8 2005 9504 0b81 66e0 82a6
|
|
133
|
+
2d1b ff6e 919d 29ad 1718 63c7 8f0b 97c8
|
|
134
|
+
e9ae 82ae 43d3
|
|
135
135
|
HEXDUMP
|
|
136
136
|
)).to eq [
|
|
137
137
|
[':status', '302'],
|
|
@@ -141,7 +141,7 @@ HEXDUMP
|
|
|
141
141
|
]
|
|
142
142
|
# https://datatracker.ietf.org/doc/html/rfc7541#appendix-C.6.2
|
|
143
143
|
expect(decoder.decode([<<HEXDUMP.split.join].pack('H*')
|
|
144
|
-
|
|
144
|
+
4883 640e ffc1 c0bf
|
|
145
145
|
HEXDUMP
|
|
146
146
|
)).to eq [
|
|
147
147
|
[':status', '307'],
|
|
@@ -151,11 +151,11 @@ HEXDUMP
|
|
|
151
151
|
]
|
|
152
152
|
# https://datatracker.ietf.org/doc/html/rfc7541#appendix-C.6.3
|
|
153
153
|
expect(decoder.decode([<<HEXDUMP.split.join].pack('H*')
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
154
|
+
88c1 6196 d07a be94 1054 d444 a820 0595
|
|
155
|
+
040b 8166 e084 a62d 1bff c05a 839b d9ab
|
|
156
|
+
77ad 94e7 821d d7f2 e6c7 b335 dfdf cd5b
|
|
157
|
+
3960 d5af 2708 7f36 72c1 ab27 0fb5 291f
|
|
158
|
+
9587 3160 65c0 03ed 4ee5 b106 3d50 07
|
|
159
159
|
HEXDUMP
|
|
160
160
|
)).to eq [
|
|
161
161
|
[':status', '200'],
|
data/spec/hpack/encoder_spec.rb
CHANGED
|
@@ -14,10 +14,10 @@ RSpec.describe HPACK::Encoder do
|
|
|
14
14
|
['date', 'Mon, 21 Oct 2013 20:13:21 GMT'],
|
|
15
15
|
['location', 'https://www.example.com']
|
|
16
16
|
])).to eq [<<HEXDUMP.split.join].pack('H*')
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
4882 6402 5885 aec3 771a 4b61 96d0 7abe
|
|
18
|
+
9410 54d4 44a8 2005 9504 0b81 66e0 82a6
|
|
19
|
+
2d1b ff6e 919d 29ad 1718 63c7 8f0b 97c8
|
|
20
|
+
e9ae 82ae 43d3
|
|
21
21
|
HEXDUMP
|
|
22
22
|
# https://datatracker.ietf.org/doc/html/rfc7541#appendix-C.6.2
|
|
23
23
|
expect(encoder.encode([
|
|
@@ -26,7 +26,7 @@ HEXDUMP
|
|
|
26
26
|
['date', 'Mon, 21 Oct 2013 20:13:21 GMT'],
|
|
27
27
|
['location', 'https://www.example.com']
|
|
28
28
|
])).to eq [<<HEXDUMP.split.join].pack('H*')
|
|
29
|
-
|
|
29
|
+
4883 640e ffc1 c0bf
|
|
30
30
|
HEXDUMP
|
|
31
31
|
# https://datatracker.ietf.org/doc/html/rfc7541#appendix-C.6.3
|
|
32
32
|
expect(encoder.encode([
|
|
@@ -37,11 +37,11 @@ HEXDUMP
|
|
|
37
37
|
['content-encoding', 'gzip'],
|
|
38
38
|
['set-cookie', 'foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1']
|
|
39
39
|
])).to eq [<<HEXDUMP.split.join].pack('H*')
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
88c1 6196 d07a be94 1054 d444 a820 0595
|
|
41
|
+
040b 8166 e084 a62d 1bff c05a 839b d9ab
|
|
42
|
+
77ad 94e7 821d d7f2 e6c7 b335 dfdf cd5b
|
|
43
|
+
3960 d5af 2708 7f36 72c1 ab27 0fb5 291f
|
|
44
|
+
9587 3160 65c0 03ed 4ee5 b106 3d50 07
|
|
45
45
|
HEXDUMP
|
|
46
46
|
end
|
|
47
47
|
end
|
data/spec/hpack/fields_spec.rb
CHANGED
|
@@ -7,9 +7,9 @@ RSpec.describe HPACK::Fields do
|
|
|
7
7
|
end
|
|
8
8
|
it 'should decode' do
|
|
9
9
|
expect(HPACK::Fields.decode([<<HEXDUMP.split.join].pack('H*'),
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
8286 8441 8a08 9d5c 0b81 70dc 79e7
|
|
11
|
+
9e40 8721 eaa8 a449 8f57 88ea 52d6
|
|
12
|
+
b0e8 3772 ff
|
|
13
13
|
HEXDUMP
|
|
14
14
|
dynamic_table)).to eq [[':method', 'GET'], [':scheme', 'http'], [':path', '/'], [':authority', '127.0.0.1:8888'], ['connection', 'keep-alive']]
|
|
15
15
|
end
|
|
@@ -3,9 +3,9 @@ require_relative 'spec_helper'
|
|
|
3
3
|
RSpec.describe StreamsContext do
|
|
4
4
|
context 'close_all' do
|
|
5
5
|
let(:streams_ctx) do
|
|
6
|
-
streams_ctx = StreamsContext.new
|
|
7
|
-
streams_ctx.new_context(1, 65_535, 65_535
|
|
8
|
-
streams_ctx.new_context(2, 65_535, 65_535
|
|
6
|
+
streams_ctx = StreamsContext.new(do_nothing_proc)
|
|
7
|
+
streams_ctx.new_context(1, 65_535, 65_535)
|
|
8
|
+
streams_ctx.new_context(2, 65_535, 65_535)
|
|
9
9
|
streams_ctx
|
|
10
10
|
end
|
|
11
11
|
it 'should close' do
|
|
@@ -17,9 +17,9 @@ RSpec.describe StreamsContext do
|
|
|
17
17
|
|
|
18
18
|
context 'close_all' do
|
|
19
19
|
let(:streams_ctx) do
|
|
20
|
-
streams_ctx = StreamsContext.new
|
|
21
|
-
streams_ctx.new_context(1, 65_535, 65_535
|
|
22
|
-
streams_ctx.new_context(2, 65_535, 65_535
|
|
20
|
+
streams_ctx = StreamsContext.new(do_nothing_proc)
|
|
21
|
+
streams_ctx.new_context(1, 65_535, 65_535)
|
|
22
|
+
streams_ctx.new_context(2, 65_535, 65_535)
|
|
23
23
|
streams_ctx
|
|
24
24
|
end
|
|
25
25
|
it 'should close' do
|
|
@@ -31,9 +31,9 @@ RSpec.describe StreamsContext do
|
|
|
31
31
|
|
|
32
32
|
context 'remove_closed' do
|
|
33
33
|
let(:streams_ctx1) do
|
|
34
|
-
streams_ctx = StreamsContext.new
|
|
35
|
-
streams_ctx.new_context(1, 65_535, 65_535
|
|
36
|
-
streams_ctx.new_context(2, 65_535, 65_535
|
|
34
|
+
streams_ctx = StreamsContext.new(do_nothing_proc)
|
|
35
|
+
streams_ctx.new_context(1, 65_535, 65_535)
|
|
36
|
+
streams_ctx.new_context(2, 65_535, 65_535)
|
|
37
37
|
streams_ctx
|
|
38
38
|
end
|
|
39
39
|
let(:data_buffer1) do
|
|
@@ -45,9 +45,9 @@ RSpec.describe StreamsContext do
|
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
let(:streams_ctx2) do
|
|
48
|
-
streams_ctx = StreamsContext.new
|
|
49
|
-
streams_ctx.new_context(1, 65_535, 65_535
|
|
50
|
-
streams_ctx.new_context(2, 65_535, 65_535
|
|
48
|
+
streams_ctx = StreamsContext.new(do_nothing_proc)
|
|
49
|
+
streams_ctx.new_context(1, 65_535, 65_535)
|
|
50
|
+
streams_ctx.new_context(2, 65_535, 65_535)
|
|
51
51
|
streams_ctx[2].state.close
|
|
52
52
|
streams_ctx
|
|
53
53
|
end
|
|
@@ -60,9 +60,9 @@ RSpec.describe StreamsContext do
|
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
let(:streams_ctx3) do
|
|
63
|
-
streams_ctx = StreamsContext.new
|
|
64
|
-
streams_ctx.new_context(1, 65_535, 65_535
|
|
65
|
-
streams_ctx.new_context(2, 65_535, 65_535
|
|
63
|
+
streams_ctx = StreamsContext.new(do_nothing_proc)
|
|
64
|
+
streams_ctx.new_context(1, 65_535, 65_535)
|
|
65
|
+
streams_ctx.new_context(2, 65_535, 65_535)
|
|
66
66
|
streams_ctx[2].state.close
|
|
67
67
|
streams_ctx
|
|
68
68
|
end
|
data/spec/utils_spec.rb
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require_relative 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe Biryani do
|
|
4
|
+
let(:data) do
|
|
5
|
+
Frame::Data.new(false, 2, 'Hello, world!', 'Howdy!')
|
|
6
|
+
end
|
|
7
|
+
let(:connection_error) do
|
|
8
|
+
ConnectionError.new(ErrorCode::NO_ERROR, 'debug')
|
|
9
|
+
end
|
|
10
|
+
let(:stream_error) do
|
|
11
|
+
StreamError.new(ErrorCode::NO_ERROR, 1, 'debug')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context 'err?' do
|
|
15
|
+
it 'should be not error' do
|
|
16
|
+
expect(Biryani.err?(data)).to eq false
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'should be error' do
|
|
20
|
+
expect(Biryani.err?(connection_error)).to be true
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'should be error' do
|
|
24
|
+
expect(Biryani.err?(stream_error)).to be true
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
context 'unwrap' do
|
|
29
|
+
it 'should unwrap' do
|
|
30
|
+
expect(Biryani.unwrap(data, 0x01)).to eq data
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'should unwrap' do
|
|
34
|
+
expect(Biryani.unwrap(connection_error, 0x01)).to be_kind_of Frame::Goaway
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'should unwrap' do
|
|
38
|
+
expect(Biryani.unwrap(stream_error, 0x01)).to be_kind_of Frame::RstStream
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: biryani
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- thekuwayama
|
|
@@ -79,6 +79,8 @@ files:
|
|
|
79
79
|
- lib/biryani/version.rb
|
|
80
80
|
- lib/biryani/window.rb
|
|
81
81
|
- spec/connection/handle_connection_window_update_spec.rb
|
|
82
|
+
- spec/connection/handle_data_spec.rb
|
|
83
|
+
- spec/connection/handle_headers_spec.rb
|
|
82
84
|
- spec/connection/handle_ping_spec.rb
|
|
83
85
|
- spec/connection/handle_rst_stream_spec.rb
|
|
84
86
|
- spec/connection/handle_settings_spec.rb
|
|
@@ -86,7 +88,6 @@ files:
|
|
|
86
88
|
- spec/connection/read_http2_magic_spec.rb
|
|
87
89
|
- spec/connection/send_spec.rb
|
|
88
90
|
- spec/connection/transition_state_send_spec.rb
|
|
89
|
-
- spec/connection/unwrap_spec.rb
|
|
90
91
|
- spec/data_buffer_spec.rb
|
|
91
92
|
- spec/frame/continuation_spec.rb
|
|
92
93
|
- spec/frame/data_spec.rb
|
|
@@ -109,6 +110,7 @@ files:
|
|
|
109
110
|
- spec/http_request_builder_spec.rb
|
|
110
111
|
- spec/spec_helper.rb
|
|
111
112
|
- spec/streams_context_spec.rb
|
|
113
|
+
- spec/utils_spec.rb
|
|
112
114
|
homepage: https://github.com/thekuwayama/biryani
|
|
113
115
|
licenses:
|
|
114
116
|
- MIT
|
|
@@ -132,6 +134,8 @@ specification_version: 4
|
|
|
132
134
|
summary: An HTTP/2 server implemented using Ruby Ractor
|
|
133
135
|
test_files:
|
|
134
136
|
- spec/connection/handle_connection_window_update_spec.rb
|
|
137
|
+
- spec/connection/handle_data_spec.rb
|
|
138
|
+
- spec/connection/handle_headers_spec.rb
|
|
135
139
|
- spec/connection/handle_ping_spec.rb
|
|
136
140
|
- spec/connection/handle_rst_stream_spec.rb
|
|
137
141
|
- spec/connection/handle_settings_spec.rb
|
|
@@ -139,7 +143,6 @@ test_files:
|
|
|
139
143
|
- spec/connection/read_http2_magic_spec.rb
|
|
140
144
|
- spec/connection/send_spec.rb
|
|
141
145
|
- spec/connection/transition_state_send_spec.rb
|
|
142
|
-
- spec/connection/unwrap_spec.rb
|
|
143
146
|
- spec/data_buffer_spec.rb
|
|
144
147
|
- spec/frame/continuation_spec.rb
|
|
145
148
|
- spec/frame/data_spec.rb
|
|
@@ -162,3 +165,4 @@ test_files:
|
|
|
162
165
|
- spec/http_request_builder_spec.rb
|
|
163
166
|
- spec/spec_helper.rb
|
|
164
167
|
- spec/streams_context_spec.rb
|
|
168
|
+
- spec/utils_spec.rb
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
require_relative '../spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe Connection do
|
|
4
|
-
context 'unwrap' do
|
|
5
|
-
let(:data) do
|
|
6
|
-
Frame::Data.new(false, 2, 'Hello, world!', 'Howdy!')
|
|
7
|
-
end
|
|
8
|
-
it 'should ensure' do
|
|
9
|
-
expect(Connection.unwrap(data, 0x01)).to eq data
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
let(:connection_error) do
|
|
13
|
-
ConnectionError.new(ErrorCode::NO_ERROR, 'debug')
|
|
14
|
-
end
|
|
15
|
-
it 'should ensure' do
|
|
16
|
-
frame = Connection.unwrap(connection_error, 0x01)
|
|
17
|
-
expect(frame).to be_kind_of Frame::Goaway
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
let(:stream_error) do
|
|
21
|
-
StreamError.new(ErrorCode::NO_ERROR, 0x01, 'debug')
|
|
22
|
-
end
|
|
23
|
-
it 'should ensure' do
|
|
24
|
-
frame = Connection.unwrap(stream_error, 0x01)
|
|
25
|
-
expect(frame).to be_kind_of Frame::RstStream
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|