biryani 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e8b17b7b795ee787a07fe5be9e453d4486fdce914609539446932e4fb988912
4
- data.tar.gz: 45f9196ca41aecf8efecaee4e29e459e20a6ac05116b8e384858f52d365c4726
3
+ metadata.gz: 890de8c1fbcd3833f63207a420161b289a4497275fbdbb747625d1350b1f0d6c
4
+ data.tar.gz: 1c587a3643953d2acbd1b0022c1ff1b228cc382cc10c75442fb99d68b370f2b4
5
5
  SHA512:
6
- metadata.gz: 13ba324d9792cde457634d20d72bb7f276772aa6b1eacd878dd82cd3f2fade7f5025472e7bf4b057208f71b68bf8f6df7e2f07bfaeda62baa0c9c6f7c5f58018
7
- data.tar.gz: ed9846fa55648102b94242338429b45d6bea100eb1427a736c5a90886c6e3933602138407f0bd474f5c3f024887100f2fc241b46c16bfa2f035ca0ce08f8c1f2
6
+ metadata.gz: fe5ed688fe4aff77533de4b37ee5e668f7904435a2c345410c4b87c85ab68af33d03b3741fc3266e605554e057c81cfe28e267b1d94e2f916718e2190d6ee948
7
+ data.tar.gz: 19cfdad4968d33626135242e33629ed5105069a30f50e377367fa0aae45e2c594e2cfa388c7ea8b635ab17541749a147c04414738633787a3b720043b38ac6aa
@@ -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 = self.class.unwrap(obj, @streams_ctx.last_stream_id)
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 = self.class.unwrap(frame, @streams_ctx.last_stream_id)
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
@@ -102,8 +108,6 @@ module Biryani
102
108
 
103
109
  break if closed?
104
110
  end
105
- ensure
106
- @streams_ctx.clear_all
107
111
  end
108
112
  # rubocop: enable Metrics/AbcSize
109
113
  # rubocop: enable Metrics/BlockLength
@@ -145,16 +149,17 @@ module Biryani
145
149
  [ping_ack]
146
150
  when FrameType::GOAWAY
147
151
  self.class.handle_goaway(frame)
148
- # TODO: logging error
152
+
149
153
  []
150
154
  when FrameType::WINDOW_UPDATE
151
155
  err = self.class.handle_connection_window_update(frame, @send_window)
152
156
  return [err] unless err.nil?
153
157
 
154
158
  max_frame_size = @peer_settings[SettingsID::SETTINGS_MAX_FRAME_SIZE]
155
- @data_buffer.take!(@send_window, @streams_ctx, max_frame_size)
159
+ @data_buffer.take!(@send_window, @streams_ctx, max_frame_size) # return DATA Frames
156
160
  else
157
- # ignore unknown frame type
161
+ # ignore UNKNOWN Frame
162
+
158
163
  []
159
164
  end
160
165
  end
@@ -166,7 +171,6 @@ module Biryani
166
171
  # rubocop: disable Metrics/AbcSize
167
172
  # rubocop: disable Metrics/CyclomaticComplexity
168
173
  # rubocop: disable Metrics/MethodLength
169
- # rubocop: disable Metrics/PerceivedComplexity
170
174
  def handle_stream_frame(frame)
171
175
  stream_id = frame.stream_id
172
176
  typ = frame.f_type
@@ -176,40 +180,32 @@ module Biryani
176
180
  max_streams = @peer_settings[SettingsID::SETTINGS_MAX_CONCURRENT_STREAMS]
177
181
  send_initial_window_size = @peer_settings[SettingsID::SETTINGS_INITIAL_WINDOW_SIZE]
178
182
  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, @proc)
183
+ obj = self.class.transition_state_recv(frame, @streams_ctx, stream_id, max_streams, send_initial_window_size, recv_initial_window_size)
180
184
  return [obj] if Biryani.err?(obj)
181
185
 
182
186
  ctx = obj
183
187
  case typ
184
188
  when FrameType::DATA
185
- # TODO: flow-control using @recv_window & ctx.recv_window
186
- ctx.content << frame.data
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
189
+ obj = self.class.handle_data(stream_id, frame.data, @recv_window, @streams_ctx, @decoder)
190
+ return [obj] if Biryani.err?(obj)
193
191
 
194
- []
192
+ obj # return WINDOW_UPDATE Frames
195
193
  when FrameType::HEADERS, FrameType::CONTINUATION
196
- ctx.fragment << frame.fragment
197
- if ctx.state.half_closed_remote?
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
194
+ err = self.class.handle_headers(frame, ctx, @decoder)
195
+ return [err] unless err.nil?
203
196
 
204
197
  []
205
198
  when FrameType::PRIORITY
206
199
  # ignore PRIORITY Frame
200
+
207
201
  []
208
202
  when FrameType::PUSH_PROMISE
209
203
  # TODO
204
+
210
205
  []
211
206
  when FrameType::RST_STREAM
212
- self.class.handle_rst_stream(frame, @streams_ctx)
207
+ self.class.handle_rst_stream(frame, ctx)
208
+
213
209
  []
214
210
  when FrameType::WINDOW_UPDATE
215
211
  err = self.class.handle_stream_window_update(frame, @streams_ctx)
@@ -219,13 +215,13 @@ module Biryani
219
215
  @data_buffer.take!(@send_window, @streams_ctx, max_frame_size)
220
216
  else
221
217
  # ignore UNKNOWN Frame
218
+
222
219
  []
223
220
  end
224
221
  end
225
222
  # rubocop: enable Metrics/AbcSize
226
223
  # rubocop: enable Metrics/CyclomaticComplexity
227
224
  # rubocop: enable Metrics/MethodLength
228
- # rubocop: enable Metrics/PerceivedComplexity
229
225
 
230
226
  def close
231
227
  @closed = true
@@ -236,39 +232,23 @@ module Biryani
236
232
  @closed
237
233
  end
238
234
 
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
235
  # @param recv_frame [Object]
255
236
  # @param streams_ctx [StreamsContext]
256
237
  # @param stream_id [Integer]
257
238
  # @param max_streams [Integer]
258
239
  # @param send_initial_window_size [Integer]
259
240
  # @param recv_initial_window_size [Integer]
260
- # @param proc [Proc]
261
241
  #
262
242
  # @return [StreamContext, StreamError, ConnectionError]
263
243
  # rubocop: disable Metrics/CyclomaticComplexity
264
244
  # 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, proc)
245
+ def self.transition_state_recv(recv_frame, streams_ctx, stream_id, max_streams, send_initial_window_size, recv_initial_window_size)
266
246
  ctx = streams_ctx[stream_id]
267
247
  return StreamError.new(ErrorCode::PROTOCOL_ERROR, stream_id, 'exceed max concurrent streams') if ctx.nil? && streams_ctx.count_active + 1 > max_streams
268
248
  return ConnectionError.new(ErrorCode::PROTOCOL_ERROR, 'even-numbered stream identifier') if ctx.nil? && stream_id.even?
269
249
  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
250
 
271
- ctx = streams_ctx.new_context(stream_id, send_initial_window_size, recv_initial_window_size, proc) if ctx.nil?
251
+ ctx = streams_ctx.new_context(stream_id, send_initial_window_size, recv_initial_window_size) if ctx.nil?
272
252
  obj = ctx.state.transition!(recv_frame, :recv)
273
253
  return obj if Biryani.err?(obj)
274
254
 
@@ -291,7 +271,7 @@ module Biryani
291
271
  streams_ctx.close_all
292
272
  true
293
273
  else
294
- streams_ctx[stream_id].state.transition!(send_frame, :send)
274
+ streams_ctx[stream_id].state.transition!(send_frame, :send) unless stream_id.zero?
295
275
  false
296
276
  end
297
277
  end
@@ -312,7 +292,7 @@ module Biryani
312
292
  # @param streams_ctx [StreamsContext]
313
293
  # @param data_buffer [DataBuffer]
314
294
  def self.send_data(io, stream_id, data, send_window, max_frame_size, streams_ctx, data_buffer)
315
- frames, remains = streams_ctx.sendable_data_frames(stream_id, data, send_window, max_frame_size)
295
+ frames, remains = streams_ctx.sendable_datas(stream_id, data, send_window, max_frame_size)
316
296
 
317
297
  frames.each do |frame|
318
298
  do_send(io, frame, false)
@@ -355,11 +335,55 @@ module Biryani
355
335
  ConnectionError.new(ErrorCode::PROTOCOL_ERROR, 'invalid connection preface') if s != CONNECTION_PREFACE
356
336
  end
357
337
 
358
- # @param rst_stream [RstStream]
338
+ # @param stream_id [Integer]
339
+ # @param data [String]
340
+ # @param recv_window [Window]
359
341
  # @param streams_ctx [StreamsContext]
360
- def self.handle_rst_stream(rst_stream, streams_ctx)
361
- stream_id = rst_stream.stream_id
362
- streams_ctx[stream_id].state.close
342
+ # @param decoder [Decoder]
343
+ #
344
+ # @return [Array<WindowUpdate>, ConnectionError]
345
+ # rubocop: disable Metrics/AbcSize
346
+ def self.handle_data(stream_id, data, recv_window, streams_ctx, decoder)
347
+ ctx = streams_ctx[stream_id]
348
+ return ConnectionError.new(ErrorCode::FLOW_CONTROL_ERROR, 'DATA Frame length exceeds flow-control window size') \
349
+ if recv_window.consume!(data.bytesize).negative? || ctx.recv_window.consume!(data.bytesize).negative?
350
+
351
+ ctx.content << data
352
+ if ctx.state.half_closed_remote?
353
+ obj = http_request(ctx.fragment.string, ctx.content.string, decoder)
354
+ return obj if Biryani.err?(obj)
355
+
356
+ ctx.stream.rx << obj
357
+ end
358
+
359
+ window_updates = []
360
+ window_updates << Frame::WindowUpdate.new(0, recv_window.capacity - recv_window.length) if recv_window.length < recv_window.capacity / 2
361
+ 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
362
+ window_updates
363
+ end
364
+ # rubocop: enable Metrics/AbcSize
365
+
366
+ # @param headers [Headers]
367
+ # @param ctx [StreamContext]
368
+ # @param decoder [Decoder]
369
+ #
370
+ # @return [nil, ConnectionError]
371
+ def self.handle_headers(headers, ctx, decoder)
372
+ ctx.fragment << headers.fragment
373
+ if ctx.state.half_closed_remote?
374
+ obj = http_request(ctx.fragment.string, ctx.content.string, decoder)
375
+ return [obj] if Biryani.err?(obj)
376
+
377
+ ctx.stream.rx << obj
378
+ end
379
+
380
+ nil
381
+ end
382
+
383
+ # @param _rst_stream [RstStream]
384
+ # @param ctx [StreamContext]
385
+ def self.handle_rst_stream(_rst_stream, ctx)
386
+ ctx.state.close
363
387
  end
364
388
 
365
389
  # @param settings [Settings]
@@ -397,7 +421,6 @@ module Biryani
397
421
  #
398
422
  # @return [nil, ConnectionError]
399
423
  def self.handle_connection_window_update(window_update, send_window)
400
- # TODO: send WINDOW_UPDATE to do the flow-conrol
401
424
  send_window.increase!(window_update.window_size_increment)
402
425
  return ConnectionError.new(ErrorCode::FLOW_CONTROL_ERROR, 'flow-control window exceeds 2^31-1') if send_window.length > 2**31 - 1
403
426
 
@@ -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.sendable_data_frames(stream_id, data, send_window, max_frame_size)
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, :recv]
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, proc)
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 sendable_data_frames(stream_id, data, send_window, max_frame_size)
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]
@@ -98,15 +98,6 @@ module Biryani
98
98
  ctx.state.close
99
99
  end
100
100
  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
101
  end
111
102
 
112
103
  class StreamContext
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
@@ -1,3 +1,3 @@
1
1
  module Biryani
2
- VERSION = '0.0.2'.freeze
2
+ VERSION = '0.0.3'.freeze
3
3
  end
@@ -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(:streams_ctx) do
9
- streams_ctx = StreamsContext.new
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, streams_ctx)
16
- expect(streams_ctx.length).to eq 2
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, do_nothing_proc)
14
- streams_ctx.new_context(2, 65_535, 65_535, do_nothing_proc)
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, do_nothing_proc)
11
- streams_ctx.new_context(2, 65_535, 65_535, do_nothing_proc)
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 2**16 - 1 + 1000
17
- expect(streams_ctx[2].send_window.length).to eq 2**16 - 1
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, do_nothing_proc)
21
- streams_ctx.new_context(2, 65_535, 65_535, do_nothing_proc)
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, do_nothing_proc)
44
- streams_ctx.new_context(2, 65_535, 65_535, do_nothing_proc)
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, do_nothing_proc)
66
- streams_ctx.new_context(2, 65_535, 65_535, do_nothing_proc)
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, do_nothing_proc)
91
- streams_ctx.new_context(2, 65_535, 65_535, do_nothing_proc)
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, do_nothing_proc)
8
- streams_ctx.new_context(2, 65_535, 65_535, do_nothing_proc)
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
 
@@ -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, do_nothing_proc)
14
- streams_ctx.new_context(2, 65_535, 65_535, do_nothing_proc)
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, do_nothing_proc)
36
- streams_ctx.new_context(2, 65_535, 65_535, do_nothing_proc)
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, do_nothing_proc)
60
- streams_ctx.new_context(2, 65_535, 65_535, do_nothing_proc)
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, do_nothing_proc)
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, do_nothing_proc)
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, do_nothing_proc)
113
- streams_ctx.new_context(2, 65_535, 65_535, do_nothing_proc)
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
@@ -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
- 8286 8441 0f77 7777 2e65 7861 6d70 6c65
13
- 2e63 6f6d
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
- 8286 84be 5808 6e6f 2d63 6163 6865
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
- 8287 85bf 400a 6375 7374 6f6d 2d6b 6579
35
- 0c63 7573 746f 6d2d 7661 6c75 65
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
- 8286 8441 8cf1 e3c2 e5f2 3a6b a0ab 90f4
50
- ff
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
- 8286 84be 5886 a8eb 1064 9cbf
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
- 8287 85bf 4088 25a8 49e9 5ba9 7d7f 8925
72
- a849 e95b b8e8 b4bf
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
- 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
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
- 4803 3330 37c1 c0bf
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
- 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
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
- 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
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
- 4883 640e ffc1 c0bf
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
- 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
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'],
@@ -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
- 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
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
- 4883 640e ffc1 c0bf
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
- 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
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
@@ -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
- 8286 8441 8a08 9d5c 0b81 70dc 79e7
11
- 9e40 8721 eaa8 a449 8f57 88ea 52d6
12
- b0e8 3772 ff
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, do_nothing_proc)
8
- streams_ctx.new_context(2, 65_535, 65_535, do_nothing_proc)
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, do_nothing_proc)
22
- streams_ctx.new_context(2, 65_535, 65_535, do_nothing_proc)
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, do_nothing_proc)
36
- streams_ctx.new_context(2, 65_535, 65_535, do_nothing_proc)
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, do_nothing_proc)
50
- streams_ctx.new_context(2, 65_535, 65_535, do_nothing_proc)
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, do_nothing_proc)
65
- streams_ctx.new_context(2, 65_535, 65_535, do_nothing_proc)
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
@@ -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.2
4
+ version: 0.0.3
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