biryani 0.0.4 → 0.0.5
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 +2 -2
- data/lib/biryani/data_buffer.rb +1 -1
- data/lib/biryani/frame/continuation.rb +4 -7
- data/lib/biryani/frame/data.rb +9 -12
- data/lib/biryani/frame/goaway.rb +6 -6
- data/lib/biryani/frame/headers.rb +25 -18
- data/lib/biryani/frame/ping.rb +5 -7
- data/lib/biryani/frame/priority.rb +6 -5
- data/lib/biryani/frame/push_promise.rb +14 -15
- data/lib/biryani/frame/rst_stream.rb +5 -5
- data/lib/biryani/frame/settings.rb +5 -5
- data/lib/biryani/frame/unknown.rb +0 -12
- data/lib/biryani/frame/window_update.rb +5 -5
- data/lib/biryani/frame.rb +5 -4
- data/lib/biryani/hpack/field.rb +42 -42
- data/lib/biryani/hpack/fields.rb +2 -1
- data/lib/biryani/hpack/huffman.rb +290 -21
- data/lib/biryani/hpack/integer.rb +10 -6
- data/lib/biryani/hpack/string.rb +6 -6
- data/lib/biryani/http_request.rb +1 -1
- data/lib/biryani/state.rb +2 -0
- data/lib/biryani/streams_context.rb +2 -6
- data/lib/biryani/version.rb +1 -1
- data/lib/biryani.rb +0 -1
- data/spec/connection/handle_data_spec.rb +2 -2
- data/spec/connection/handle_headers_spec.rb +1 -1
- data/spec/frame/continuation_spec.rb +2 -2
- data/spec/frame/data_spec.rb +1 -1
- data/spec/frame/goaway_spec.rb +1 -1
- data/spec/frame/headers_spec.rb +2 -2
- data/spec/frame/ping_spec.rb +1 -1
- data/spec/frame/priority_spec.rb +1 -1
- data/spec/frame/push_promise_spec.rb +1 -1
- data/spec/frame/rst_stream_spec.rb +1 -1
- data/spec/frame/settings_spec.rb +1 -1
- data/spec/frame/window_update_spec.rb +1 -1
- data/spec/hpack/field_spec.rb +10 -9
- data/spec/hpack/huffman_spec.rb +4 -4
- data/spec/hpack/integer_spec.rb +5 -5
- data/spec/hpack/string_spec.rb +2 -2
- metadata +1 -1
|
@@ -262,46 +262,315 @@ module Biryani
|
|
|
262
262
|
11111111111111111111101110
|
|
263
263
|
111111111111111111111111111111
|
|
264
264
|
].freeze
|
|
265
|
-
DECODE_TABLE =
|
|
266
|
-
|
|
265
|
+
DECODE_TABLE = [
|
|
266
|
+
[0b1111111111000, 13],
|
|
267
|
+
[0b11111111111111111011000, 23],
|
|
268
|
+
[0b1111111111111111111111100010, 28],
|
|
269
|
+
[0b1111111111111111111111100011, 28],
|
|
270
|
+
[0b1111111111111111111111100100, 28],
|
|
271
|
+
[0b1111111111111111111111100101, 28],
|
|
272
|
+
[0b1111111111111111111111100110, 28],
|
|
273
|
+
[0b1111111111111111111111100111, 28],
|
|
274
|
+
[0b1111111111111111111111101000, 28],
|
|
275
|
+
[0b111111111111111111101010, 24],
|
|
276
|
+
[0b111111111111111111111111111100, 30],
|
|
277
|
+
[0b1111111111111111111111101001, 28],
|
|
278
|
+
[0b1111111111111111111111101010, 28],
|
|
279
|
+
[0b111111111111111111111111111101, 30],
|
|
280
|
+
[0b1111111111111111111111101011, 28],
|
|
281
|
+
[0b1111111111111111111111101100, 28],
|
|
282
|
+
[0b1111111111111111111111101101, 28],
|
|
283
|
+
[0b1111111111111111111111101110, 28],
|
|
284
|
+
[0b1111111111111111111111101111, 28],
|
|
285
|
+
[0b1111111111111111111111110000, 28],
|
|
286
|
+
[0b1111111111111111111111110001, 28],
|
|
287
|
+
[0b1111111111111111111111110010, 28],
|
|
288
|
+
[0b111111111111111111111111111110, 30],
|
|
289
|
+
[0b1111111111111111111111110011, 28],
|
|
290
|
+
[0b1111111111111111111111110100, 28],
|
|
291
|
+
[0b1111111111111111111111110101, 28],
|
|
292
|
+
[0b1111111111111111111111110110, 28],
|
|
293
|
+
[0b1111111111111111111111110111, 28],
|
|
294
|
+
[0b1111111111111111111111111000, 28],
|
|
295
|
+
[0b1111111111111111111111111001, 28],
|
|
296
|
+
[0b1111111111111111111111111010, 28],
|
|
297
|
+
[0b1111111111111111111111111011, 28],
|
|
298
|
+
[0b010100, 6],
|
|
299
|
+
[0b1111111000, 10],
|
|
300
|
+
[0b1111111001, 10],
|
|
301
|
+
[0b111111111010, 12],
|
|
302
|
+
[0b1111111111001, 13],
|
|
303
|
+
[0b010101, 6],
|
|
304
|
+
[0b11111000, 8],
|
|
305
|
+
[0b11111111010, 11],
|
|
306
|
+
[0b1111111010, 10],
|
|
307
|
+
[0b1111111011, 10],
|
|
308
|
+
[0b11111001, 8],
|
|
309
|
+
[0b11111111011, 11],
|
|
310
|
+
[0b11111010, 8],
|
|
311
|
+
[0b010110, 6],
|
|
312
|
+
[0b010111, 6],
|
|
313
|
+
[0b011000, 6],
|
|
314
|
+
[0b00000, 5],
|
|
315
|
+
[0b00001, 5],
|
|
316
|
+
[0b00010, 5],
|
|
317
|
+
[0b011001, 6],
|
|
318
|
+
[0b011010, 6],
|
|
319
|
+
[0b011011, 6],
|
|
320
|
+
[0b011100, 6],
|
|
321
|
+
[0b011101, 6],
|
|
322
|
+
[0b011110, 6],
|
|
323
|
+
[0b011111, 6],
|
|
324
|
+
[0b1011100, 7],
|
|
325
|
+
[0b11111011, 8],
|
|
326
|
+
[0b111111111111100, 15],
|
|
327
|
+
[0b100000, 6],
|
|
328
|
+
[0b111111111011, 12],
|
|
329
|
+
[0b1111111100, 10],
|
|
330
|
+
[0b1111111111010, 13],
|
|
331
|
+
[0b100001, 6],
|
|
332
|
+
[0b1011101, 7],
|
|
333
|
+
[0b1011110, 7],
|
|
334
|
+
[0b1011111, 7],
|
|
335
|
+
[0b1100000, 7],
|
|
336
|
+
[0b1100001, 7],
|
|
337
|
+
[0b1100010, 7],
|
|
338
|
+
[0b1100011, 7],
|
|
339
|
+
[0b1100100, 7],
|
|
340
|
+
[0b1100101, 7],
|
|
341
|
+
[0b1100110, 7],
|
|
342
|
+
[0b1100111, 7],
|
|
343
|
+
[0b1101000, 7],
|
|
344
|
+
[0b1101001, 7],
|
|
345
|
+
[0b1101010, 7],
|
|
346
|
+
[0b1101011, 7],
|
|
347
|
+
[0b1101100, 7],
|
|
348
|
+
[0b1101101, 7],
|
|
349
|
+
[0b1101110, 7],
|
|
350
|
+
[0b1101111, 7],
|
|
351
|
+
[0b1110000, 7],
|
|
352
|
+
[0b1110001, 7],
|
|
353
|
+
[0b1110010, 7],
|
|
354
|
+
[0b11111100, 8],
|
|
355
|
+
[0b1110011, 7],
|
|
356
|
+
[0b11111101, 8],
|
|
357
|
+
[0b1111111111011, 13],
|
|
358
|
+
[0b1111111111111110000, 19],
|
|
359
|
+
[0b1111111111100, 13],
|
|
360
|
+
[0b11111111111100, 14],
|
|
361
|
+
[0b100010, 6],
|
|
362
|
+
[0b111111111111101, 15],
|
|
363
|
+
[0b00011, 5],
|
|
364
|
+
[0b100011, 6],
|
|
365
|
+
[0b00100, 5],
|
|
366
|
+
[0b100100, 6],
|
|
367
|
+
[0b00101, 5],
|
|
368
|
+
[0b100101, 6],
|
|
369
|
+
[0b100110, 6],
|
|
370
|
+
[0b100111, 6],
|
|
371
|
+
[0b00110, 5],
|
|
372
|
+
[0b1110100, 7],
|
|
373
|
+
[0b1110101, 7],
|
|
374
|
+
[0b101000, 6],
|
|
375
|
+
[0b101001, 6],
|
|
376
|
+
[0b101010, 6],
|
|
377
|
+
[0b00111, 5],
|
|
378
|
+
[0b101011, 6],
|
|
379
|
+
[0b1110110, 7],
|
|
380
|
+
[0b101100, 6],
|
|
381
|
+
[0b01000, 5],
|
|
382
|
+
[0b01001, 5],
|
|
383
|
+
[0b101101, 6],
|
|
384
|
+
[0b1110111, 7],
|
|
385
|
+
[0b1111000, 7],
|
|
386
|
+
[0b1111001, 7],
|
|
387
|
+
[0b1111010, 7],
|
|
388
|
+
[0b1111011, 7],
|
|
389
|
+
[0b111111111111110, 15],
|
|
390
|
+
[0b11111111100, 11],
|
|
391
|
+
[0b11111111111101, 14],
|
|
392
|
+
[0b1111111111101, 13],
|
|
393
|
+
[0b1111111111111111111111111100, 28],
|
|
394
|
+
[0b11111111111111100110, 20],
|
|
395
|
+
[0b1111111111111111010010, 22],
|
|
396
|
+
[0b11111111111111100111, 20],
|
|
397
|
+
[0b11111111111111101000, 20],
|
|
398
|
+
[0b1111111111111111010011, 22],
|
|
399
|
+
[0b1111111111111111010100, 22],
|
|
400
|
+
[0b1111111111111111010101, 22],
|
|
401
|
+
[0b11111111111111111011001, 23],
|
|
402
|
+
[0b1111111111111111010110, 22],
|
|
403
|
+
[0b11111111111111111011010, 23],
|
|
404
|
+
[0b11111111111111111011011, 23],
|
|
405
|
+
[0b11111111111111111011100, 23],
|
|
406
|
+
[0b11111111111111111011101, 23],
|
|
407
|
+
[0b11111111111111111011110, 23],
|
|
408
|
+
[0b111111111111111111101011, 24],
|
|
409
|
+
[0b11111111111111111011111, 23],
|
|
410
|
+
[0b111111111111111111101100, 24],
|
|
411
|
+
[0b111111111111111111101101, 24],
|
|
412
|
+
[0b1111111111111111010111, 22],
|
|
413
|
+
[0b11111111111111111100000, 23],
|
|
414
|
+
[0b111111111111111111101110, 24],
|
|
415
|
+
[0b11111111111111111100001, 23],
|
|
416
|
+
[0b11111111111111111100010, 23],
|
|
417
|
+
[0b11111111111111111100011, 23],
|
|
418
|
+
[0b11111111111111111100100, 23],
|
|
419
|
+
[0b111111111111111011100, 21],
|
|
420
|
+
[0b1111111111111111011000, 22],
|
|
421
|
+
[0b11111111111111111100101, 23],
|
|
422
|
+
[0b1111111111111111011001, 22],
|
|
423
|
+
[0b11111111111111111100110, 23],
|
|
424
|
+
[0b11111111111111111100111, 23],
|
|
425
|
+
[0b111111111111111111101111, 24],
|
|
426
|
+
[0b1111111111111111011010, 22],
|
|
427
|
+
[0b111111111111111011101, 21],
|
|
428
|
+
[0b11111111111111101001, 20],
|
|
429
|
+
[0b1111111111111111011011, 22],
|
|
430
|
+
[0b1111111111111111011100, 22],
|
|
431
|
+
[0b11111111111111111101000, 23],
|
|
432
|
+
[0b11111111111111111101001, 23],
|
|
433
|
+
[0b111111111111111011110, 21],
|
|
434
|
+
[0b11111111111111111101010, 23],
|
|
435
|
+
[0b1111111111111111011101, 22],
|
|
436
|
+
[0b1111111111111111011110, 22],
|
|
437
|
+
[0b111111111111111111110000, 24],
|
|
438
|
+
[0b111111111111111011111, 21],
|
|
439
|
+
[0b1111111111111111011111, 22],
|
|
440
|
+
[0b11111111111111111101011, 23],
|
|
441
|
+
[0b11111111111111111101100, 23],
|
|
442
|
+
[0b111111111111111100000, 21],
|
|
443
|
+
[0b111111111111111100001, 21],
|
|
444
|
+
[0b1111111111111111100000, 22],
|
|
445
|
+
[0b111111111111111100010, 21],
|
|
446
|
+
[0b11111111111111111101101, 23],
|
|
447
|
+
[0b1111111111111111100001, 22],
|
|
448
|
+
[0b11111111111111111101110, 23],
|
|
449
|
+
[0b11111111111111111101111, 23],
|
|
450
|
+
[0b11111111111111101010, 20],
|
|
451
|
+
[0b1111111111111111100010, 22],
|
|
452
|
+
[0b1111111111111111100011, 22],
|
|
453
|
+
[0b1111111111111111100100, 22],
|
|
454
|
+
[0b11111111111111111110000, 23],
|
|
455
|
+
[0b1111111111111111100101, 22],
|
|
456
|
+
[0b1111111111111111100110, 22],
|
|
457
|
+
[0b11111111111111111110001, 23],
|
|
458
|
+
[0b11111111111111111111100000, 26],
|
|
459
|
+
[0b11111111111111111111100001, 26],
|
|
460
|
+
[0b11111111111111101011, 20],
|
|
461
|
+
[0b1111111111111110001, 19],
|
|
462
|
+
[0b1111111111111111100111, 22],
|
|
463
|
+
[0b11111111111111111110010, 23],
|
|
464
|
+
[0b1111111111111111101000, 22],
|
|
465
|
+
[0b1111111111111111111101100, 25],
|
|
466
|
+
[0b11111111111111111111100010, 26],
|
|
467
|
+
[0b11111111111111111111100011, 26],
|
|
468
|
+
[0b11111111111111111111100100, 26],
|
|
469
|
+
[0b111111111111111111111011110, 27],
|
|
470
|
+
[0b111111111111111111111011111, 27],
|
|
471
|
+
[0b11111111111111111111100101, 26],
|
|
472
|
+
[0b111111111111111111110001, 24],
|
|
473
|
+
[0b1111111111111111111101101, 25],
|
|
474
|
+
[0b1111111111111110010, 19],
|
|
475
|
+
[0b111111111111111100011, 21],
|
|
476
|
+
[0b11111111111111111111100110, 26],
|
|
477
|
+
[0b111111111111111111111100000, 27],
|
|
478
|
+
[0b111111111111111111111100001, 27],
|
|
479
|
+
[0b11111111111111111111100111, 26],
|
|
480
|
+
[0b111111111111111111111100010, 27],
|
|
481
|
+
[0b111111111111111111110010, 24],
|
|
482
|
+
[0b111111111111111100100, 21],
|
|
483
|
+
[0b111111111111111100101, 21],
|
|
484
|
+
[0b11111111111111111111101000, 26],
|
|
485
|
+
[0b11111111111111111111101001, 26],
|
|
486
|
+
[0b1111111111111111111111111101, 28],
|
|
487
|
+
[0b111111111111111111111100011, 27],
|
|
488
|
+
[0b111111111111111111111100100, 27],
|
|
489
|
+
[0b111111111111111111111100101, 27],
|
|
490
|
+
[0b11111111111111101100, 20],
|
|
491
|
+
[0b111111111111111111110011, 24],
|
|
492
|
+
[0b11111111111111101101, 20],
|
|
493
|
+
[0b111111111111111100110, 21],
|
|
494
|
+
[0b1111111111111111101001, 22],
|
|
495
|
+
[0b111111111111111100111, 21],
|
|
496
|
+
[0b111111111111111101000, 21],
|
|
497
|
+
[0b11111111111111111110011, 23],
|
|
498
|
+
[0b1111111111111111101010, 22],
|
|
499
|
+
[0b1111111111111111101011, 22],
|
|
500
|
+
[0b1111111111111111111101110, 25],
|
|
501
|
+
[0b1111111111111111111101111, 25],
|
|
502
|
+
[0b111111111111111111110100, 24],
|
|
503
|
+
[0b111111111111111111110101, 24],
|
|
504
|
+
[0b11111111111111111111101010, 26],
|
|
505
|
+
[0b11111111111111111110100, 23],
|
|
506
|
+
[0b11111111111111111111101011, 26],
|
|
507
|
+
[0b111111111111111111111100110, 27],
|
|
508
|
+
[0b11111111111111111111101100, 26],
|
|
509
|
+
[0b11111111111111111111101101, 26],
|
|
510
|
+
[0b111111111111111111111100111, 27],
|
|
511
|
+
[0b111111111111111111111101000, 27],
|
|
512
|
+
[0b111111111111111111111101001, 27],
|
|
513
|
+
[0b111111111111111111111101010, 27],
|
|
514
|
+
[0b111111111111111111111101011, 27],
|
|
515
|
+
[0b1111111111111111111111111110, 28],
|
|
516
|
+
[0b111111111111111111111101100, 27],
|
|
517
|
+
[0b111111111111111111111101101, 27],
|
|
518
|
+
[0b111111111111111111111101110, 27],
|
|
519
|
+
[0b111111111111111111111101111, 27],
|
|
520
|
+
[0b111111111111111111111110000, 27],
|
|
521
|
+
[0b11111111111111111111101110, 26],
|
|
522
|
+
[0b111111111111111111111111111111, 30]
|
|
523
|
+
].each_with_index.to_h.freeze
|
|
524
|
+
EOS = (1 << 30) - 1
|
|
267
525
|
|
|
268
526
|
private_constant :ENCODE_TABLE, :DECODE_TABLE, :EOS
|
|
269
527
|
Ractor.make_shareable(ENCODE_TABLE)
|
|
270
528
|
Ractor.make_shareable(DECODE_TABLE)
|
|
271
|
-
Ractor.make_shareable(EOS)
|
|
272
529
|
|
|
273
530
|
# @param s [String]
|
|
274
531
|
#
|
|
275
532
|
# @return [String]
|
|
276
533
|
def self.encode(s)
|
|
277
|
-
bits = s.bytes.map { |sym| ENCODE_TABLE[sym] }
|
|
278
|
-
bits << '1' * ((8 - bits.bytesize) % 8)
|
|
279
|
-
[bits].pack('B*')
|
|
280
|
-
end
|
|
534
|
+
bits = s.bytes.map { |sym| ENCODE_TABLE[sym] }
|
|
281
535
|
|
|
282
|
-
|
|
536
|
+
acc = IO::Buffer.new(bits.sum(&:bytesize))
|
|
537
|
+
offset = 0
|
|
538
|
+
bits.each do |s|
|
|
539
|
+
acc.set_string(s, offset)
|
|
540
|
+
offset += s.bytesize
|
|
541
|
+
end
|
|
283
542
|
|
|
284
|
-
|
|
543
|
+
[acc.get_string.ljust((acc.size + 7) & ~7, '1')].pack('B*')
|
|
544
|
+
end
|
|
545
|
+
|
|
546
|
+
# @param io [IO::Buffer]
|
|
547
|
+
# @param cursor [Integer]
|
|
548
|
+
# @param length [Integer]
|
|
285
549
|
#
|
|
286
550
|
# @raise [HuffmanDecodeError]
|
|
287
551
|
#
|
|
288
552
|
# @return [String]
|
|
289
|
-
def self.decode(
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
553
|
+
def self.decode(io, cursor, length)
|
|
554
|
+
res = ''.b
|
|
555
|
+
bits = 0
|
|
556
|
+
bits_len = 0
|
|
557
|
+
bytes = io.get_values([:U8] * length, cursor)
|
|
558
|
+
(length * 8).times do |i|
|
|
559
|
+
bits_len += 1
|
|
560
|
+
bits += 1 if (bytes[i / 8] & (1 << 7 - (i % 8))).positive?
|
|
561
|
+
raise Error::HuffmanDecodeError if bits == EOS
|
|
294
562
|
|
|
295
|
-
if (chr = DECODE_TABLE[
|
|
296
|
-
|
|
297
|
-
|
|
563
|
+
if (chr = DECODE_TABLE[[bits, bits_len]])
|
|
564
|
+
res << chr
|
|
565
|
+
bits = 0
|
|
566
|
+
bits_len = 0
|
|
567
|
+
else
|
|
568
|
+
bits <<= 1
|
|
298
569
|
end
|
|
299
|
-
|
|
300
|
-
acc
|
|
301
570
|
end
|
|
302
|
-
raise Error::HuffmanDecodeError if
|
|
571
|
+
raise Error::HuffmanDecodeError if bits_len.positive? && bits != (2 << bits_len) - 2 || bits_len >= 8
|
|
303
572
|
|
|
304
|
-
res
|
|
573
|
+
res
|
|
305
574
|
end
|
|
306
575
|
end
|
|
307
576
|
# rubocop: enable Metrics/ModuleLength
|
|
@@ -40,26 +40,30 @@ module Biryani
|
|
|
40
40
|
bytes.pack('C*')
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
# @param
|
|
43
|
+
# @param io [IO::Buffer]
|
|
44
44
|
# @param cursor [Integer]
|
|
45
45
|
# @param n [Integer]
|
|
46
46
|
#
|
|
47
47
|
# @return [Integer]
|
|
48
48
|
# @return [Integer]
|
|
49
|
-
def self.decode(
|
|
49
|
+
def self.decode(io, n, cursor)
|
|
50
50
|
limit = (1 << n) - 1
|
|
51
|
-
h =
|
|
51
|
+
h = io.get_value(:U8, cursor)
|
|
52
52
|
return [h & limit, cursor + 1] if (h & limit) != limit
|
|
53
53
|
|
|
54
54
|
res = limit
|
|
55
|
-
|
|
55
|
+
c = cursor + 1
|
|
56
|
+
i = 0
|
|
57
|
+
loop do
|
|
58
|
+
byte = io.get_value(:U8, c + i)
|
|
56
59
|
res += (byte & 127) * 2**(i * 7)
|
|
57
|
-
cursor += 1
|
|
58
60
|
|
|
59
61
|
break if (byte & 128).zero?
|
|
62
|
+
|
|
63
|
+
i += 1
|
|
60
64
|
end
|
|
61
65
|
|
|
62
|
-
[res,
|
|
66
|
+
[res, c + i + 1]
|
|
63
67
|
end
|
|
64
68
|
end
|
|
65
69
|
end
|
data/lib/biryani/hpack/string.rb
CHANGED
|
@@ -23,17 +23,17 @@ module Biryani
|
|
|
23
23
|
Integer.encode(res.bytesize, 7, mask) + res
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
# @param
|
|
26
|
+
# @param io [IO::Buffer]
|
|
27
27
|
# @param cursor [Integer]
|
|
28
28
|
#
|
|
29
29
|
# @return [String]
|
|
30
30
|
# @return [Integer]
|
|
31
|
-
def self.decode(
|
|
32
|
-
h = (
|
|
33
|
-
len, c = Integer.decode(
|
|
34
|
-
return [Huffman.decode(
|
|
31
|
+
def self.decode(io, cursor)
|
|
32
|
+
h = (io.get_value(:U8, cursor) & 0b10000000).positive?
|
|
33
|
+
len, c = Integer.decode(io, 7, cursor)
|
|
34
|
+
return [Huffman.decode(io, c, len), c + len] if h
|
|
35
35
|
|
|
36
|
-
[
|
|
36
|
+
[io.get_string(c, len), c + len]
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
end
|
data/lib/biryani/http_request.rb
CHANGED
data/lib/biryani/state.rb
CHANGED
|
@@ -84,16 +84,12 @@ 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].fragment.close
|
|
88
|
-
@h[id].content.close
|
|
89
87
|
end
|
|
90
88
|
end
|
|
91
89
|
|
|
92
90
|
def close_all
|
|
93
91
|
each do |ctx|
|
|
94
92
|
ctx.tx.close
|
|
95
|
-
ctx.fragment.close
|
|
96
|
-
ctx.content.close
|
|
97
93
|
ctx.state.close
|
|
98
94
|
end
|
|
99
95
|
end
|
|
@@ -111,8 +107,8 @@ module Biryani
|
|
|
111
107
|
@stream = Stream.new(@tx, stream_id, proc)
|
|
112
108
|
@send_window = Window.new(send_initial_window_size)
|
|
113
109
|
@recv_window = Window.new(recv_initial_window_size)
|
|
114
|
-
@fragment =
|
|
115
|
-
@content =
|
|
110
|
+
@fragment = ''.b
|
|
111
|
+
@content = ''.b
|
|
116
112
|
@state = State.new
|
|
117
113
|
end
|
|
118
114
|
|
data/lib/biryani/version.rb
CHANGED
data/lib/biryani.rb
CHANGED
|
@@ -17,7 +17,7 @@ RSpec.describe Connection do
|
|
|
17
17
|
end
|
|
18
18
|
it 'should handle' do
|
|
19
19
|
expect(Connection.handle_data(2, 'Hello, world!', recv_window1, streams_ctx1, decoder)).to eq []
|
|
20
|
-
expect(streams_ctx1[2].content
|
|
20
|
+
expect(streams_ctx1[2].content).to eq 'Hello, world!'
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
let(:recv_window2) do
|
|
@@ -37,7 +37,7 @@ RSpec.describe Connection do
|
|
|
37
37
|
expect(frames.map(&:f_type)).to eq [FrameType::WINDOW_UPDATE, FrameType::WINDOW_UPDATE]
|
|
38
38
|
expect(frames.map(&:stream_id)).to eq [0, 2]
|
|
39
39
|
expect(frames.map(&:window_size_increment)).to eq [65_535 / 2 + 13, 65_535 / 2 + 13]
|
|
40
|
-
expect(streams_ctx2[2].content
|
|
40
|
+
expect(streams_ctx2[2].content).to eq 'Hello, world!'
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
let(:recv_window3) do
|
|
@@ -17,7 +17,7 @@ RSpec.describe Frame::Continuation do
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
let(:continuation3) do
|
|
20
|
-
Frame::Continuation.read(
|
|
20
|
+
Frame::Continuation.read(''.b, 0, 50)
|
|
21
21
|
end
|
|
22
22
|
it 'should decode' do
|
|
23
23
|
expect(continuation3.f_type).to eq FrameType::CONTINUATION
|
|
@@ -27,7 +27,7 @@ RSpec.describe Frame::Continuation do
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
let(:continuation4) do
|
|
30
|
-
Frame::Continuation.read("\
|
|
30
|
+
Frame::Continuation.read("\x74\x68\x69\x73\x20\x69\x73\x20\x64\x75\x6d\x6d\x79".b, 9, 50)
|
|
31
31
|
end
|
|
32
32
|
it 'should decode' do
|
|
33
33
|
expect(continuation4.f_type).to eq FrameType::CONTINUATION
|
data/spec/frame/data_spec.rb
CHANGED
|
@@ -10,7 +10,7 @@ RSpec.describe Frame::Data do
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
let(:data2) do
|
|
13
|
-
Frame::Data.read("\
|
|
13
|
+
Frame::Data.read("\x06\x48\x65\x6c\x6c\x6f\x2c\x20\x77\x6f\x72\x6c\x64\x21\x48\x6f\x77\x64\x79\x21".b, 8, 2)
|
|
14
14
|
end
|
|
15
15
|
it 'should decode' do
|
|
16
16
|
expect(data2.f_type).to eq FrameType::DATA
|
data/spec/frame/goaway_spec.rb
CHANGED
|
@@ -10,7 +10,7 @@ RSpec.describe Frame::Goaway do
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
let(:goaway2) do
|
|
13
|
-
Frame::Goaway.read("\x00\x00\
|
|
13
|
+
Frame::Goaway.read("\x00\x00\x00\x1e\x00\x00\x00\x09\x68\x70\x61\x63\x6b\x20\x69\x73\x20\x62\x72\x6f\x6b\x65\x6e".b, 7, 0)
|
|
14
14
|
end
|
|
15
15
|
it 'should decode' do
|
|
16
16
|
expect(goaway2.f_type).to eq FrameType::GOAWAY
|
data/spec/frame/headers_spec.rb
CHANGED
|
@@ -18,7 +18,7 @@ RSpec.describe Frame::Headers do
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
let(:headers3) do
|
|
21
|
-
Frame::Headers.read("\
|
|
21
|
+
Frame::Headers.read("\x74\x68\x69\x73\x20\x69\x73\x20\x64\x75\x6d\x6d\x79".b, 4, 1)
|
|
22
22
|
end
|
|
23
23
|
it 'should decode' do
|
|
24
24
|
expect(headers3.f_type).to eq FrameType::HEADERS
|
|
@@ -34,7 +34,7 @@ RSpec.describe Frame::Headers do
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
let(:headers4) do
|
|
37
|
-
Frame::Headers.read("\
|
|
37
|
+
Frame::Headers.read("\x10\x00\x00\x00\x14\x0a\x74\x68\x69\x73\x20\x69\x73\x20\x64\x75\x6d\x6d\x79\x54\x68\x69\x73\x20\x69\x73\x20\x70\x61\x64\x64\x69\x6e\x67\x2e".b, 44, 3)
|
|
38
38
|
end
|
|
39
39
|
it 'should decode' do
|
|
40
40
|
expect(headers4.f_type).to eq FrameType::HEADERS
|
data/spec/frame/ping_spec.rb
CHANGED
|
@@ -10,7 +10,7 @@ RSpec.describe Frame::Ping do
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
let(:ping2) do
|
|
13
|
-
Frame::Ping.read("\
|
|
13
|
+
Frame::Ping.read("\x64\x65\x61\x64\x62\x65\x65\x66".b, 0, 0)
|
|
14
14
|
end
|
|
15
15
|
it 'should decode' do
|
|
16
16
|
expect(ping2.f_type).to eq FrameType::PING
|
data/spec/frame/priority_spec.rb
CHANGED
|
@@ -10,7 +10,7 @@ RSpec.describe Frame::Priority do
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
let(:priority2) do
|
|
13
|
-
Frame::Priority.read("\x00\x00\
|
|
13
|
+
Frame::Priority.read("\x00\x00\x00\x0b\x08".b, 0, 9)
|
|
14
14
|
end
|
|
15
15
|
it 'should decode' do
|
|
16
16
|
expect(priority2.f_type).to eq FrameType::PRIORITY
|
|
@@ -10,7 +10,7 @@ RSpec.describe Frame::PushPromise do
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
let(:push_promise2) do
|
|
13
|
-
Frame::PushPromise.read("\
|
|
13
|
+
Frame::PushPromise.read("\x06\x00\x00\x00\x0c\x74\x68\x69\x73\x20\x69\x73\x20\x64\x75\x6d\x6d\x79\x48\x6f\x77\x64\x79\x21".b, 12, 10)
|
|
14
14
|
end
|
|
15
15
|
it 'should decode' do
|
|
16
16
|
expect(push_promise2.f_type).to eq FrameType::PUSH_PROMISE
|
|
@@ -10,7 +10,7 @@ RSpec.describe Frame::RstStream do
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
let(:rst_stream2) do
|
|
13
|
-
Frame::RstStream.read("\x00\x00\
|
|
13
|
+
Frame::RstStream.read("\x00\x00\x00\x08".b, 0, 5)
|
|
14
14
|
end
|
|
15
15
|
it 'should decode' do
|
|
16
16
|
expect(rst_stream2.f_type).to eq FrameType::RST_STREAM
|
data/spec/frame/settings_spec.rb
CHANGED
|
@@ -10,7 +10,7 @@ RSpec.describe Frame::Settings do
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
let(:settings2) do
|
|
13
|
-
Frame::Settings.read("\x00\
|
|
13
|
+
Frame::Settings.read("\x00\x01\x00\x00\x20\x00\x00\x03\x00\x00\x13\x88".b, 0, 0)
|
|
14
14
|
end
|
|
15
15
|
it 'should decode' do
|
|
16
16
|
expect(settings2.f_type).to eq FrameType::SETTINGS
|
|
@@ -10,7 +10,7 @@ RSpec.describe Frame::WindowUpdate do
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
let(:window_update2) do
|
|
13
|
-
Frame::WindowUpdate.read("\x00\x00\
|
|
13
|
+
Frame::WindowUpdate.read("\x00\x00\x03\xe8".b, 0, 50)
|
|
14
14
|
end
|
|
15
15
|
it 'should decode' do
|
|
16
16
|
expect(window_update2.f_type).to eq FrameType::WINDOW_UPDATE
|
data/spec/hpack/field_spec.rb
CHANGED
|
@@ -18,25 +18,26 @@ RSpec.describe HPACK::Field do
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
it 'should decode' do
|
|
21
|
-
expect(HPACK::Field.decode("\x82".b, cursor, dynamic_table)).to eq [%w[:method GET], 1]
|
|
22
|
-
expect(HPACK::Field.decode("\x48\x82\x64\x02".b, cursor, dynamic_table)).to eq [%w[:status 302], 4]
|
|
23
|
-
expect(HPACK::Field.decode("\x6e\x91\x9d\x29\xad\x17\x18\x63\xc7\x8f\x0b\x97\xc8\xe9\xae\x82\xae\x43\xd3".b, cursor, dynamic_table))
|
|
24
|
-
|
|
25
|
-
expect(HPACK::Field.decode("\
|
|
21
|
+
expect(HPACK::Field.decode(IO::Buffer.for("\x82".b), cursor, dynamic_table)).to eq [%w[:method GET], 1]
|
|
22
|
+
expect(HPACK::Field.decode(IO::Buffer.for("\x48\x82\x64\x02".b), cursor, dynamic_table)).to eq [%w[:status 302], 4]
|
|
23
|
+
expect(HPACK::Field.decode(IO::Buffer.for("\x6e\x91\x9d\x29\xad\x17\x18\x63\xc7\x8f\x0b\x97\xc8\xe9\xae\x82\xae\x43\xd3".b), cursor, dynamic_table))
|
|
24
|
+
.to eq [%w[location https://www.example.com], 19]
|
|
25
|
+
expect(HPACK::Field.decode(IO::Buffer.for("\x40\x88\x25\xa8\x49\xe9\x5b\xa9\x7d\x7f\x89\x25\xa8\x49\xe9\x5a\x72\x8e\x42\xd9".b), cursor, dynamic_table)).to eq [%w[custom-key custom-header], 20]
|
|
26
|
+
expect(HPACK::Field.decode(IO::Buffer.for("\x10\x08\x70\x61\x73\x73\x77\x6f\x72\x64\x06\x73\x65\x63\x72\x65\x74".b), cursor, dynamic_table)).to eq [%w[password secret], 17]
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
it 'should decode' do
|
|
29
|
-
expect(HPACK::Field.decode("\x40\x88\x25\xa8\x49\xe9\x5b\xa9\x7d\x7f\x89\x25\xa8\x49\xe9\x5a\x72\x8e\x42\xd9".b, cursor, dynamic_table)).to eq [%w[custom-key custom-header], 20]
|
|
30
|
+
expect(HPACK::Field.decode(IO::Buffer.for("\x40\x88\x25\xa8\x49\xe9\x5b\xa9\x7d\x7f\x89\x25\xa8\x49\xe9\x5a\x72\x8e\x42\xd9".b), cursor, dynamic_table)).to eq [%w[custom-key custom-header], 20]
|
|
30
31
|
expect(dynamic_table.limit).to eq 4096
|
|
31
32
|
expect(dynamic_table.size).to eq 'custom-keycustom-header'.bytesize + 32
|
|
32
|
-
expect(HPACK::Field.decode("\x20".b, cursor, dynamic_table)).to eq [nil, 1]
|
|
33
|
+
expect(HPACK::Field.decode(IO::Buffer.for("\x20".b), cursor, dynamic_table)).to eq [nil, 1]
|
|
33
34
|
expect(dynamic_table.limit).to eq 4096
|
|
34
35
|
expect(dynamic_table.size).to eq 0
|
|
35
36
|
end
|
|
36
37
|
|
|
37
38
|
it 'should not decode' do
|
|
38
|
-
expect { HPACK::Field.decode("\xbe".b, cursor, dynamic_table) }.to raise_error HPACK::Error::HPACKDecodeError
|
|
39
|
-
expect { HPACK::Field.decode("\x3f\xe2\x1f".b, cursor, dynamic_table) }.to raise_error HPACK::Error::HPACKDecodeError
|
|
39
|
+
expect { HPACK::Field.decode(IO::Buffer.for("\xbe".b), cursor, dynamic_table) }.to raise_error HPACK::Error::HPACKDecodeError
|
|
40
|
+
expect { HPACK::Field.decode(IO::Buffer.for("\x3f\xe2\x1f".b), cursor, dynamic_table) }.to raise_error HPACK::Error::HPACKDecodeError
|
|
40
41
|
end
|
|
41
42
|
end
|
|
42
43
|
end
|
data/spec/hpack/huffman_spec.rb
CHANGED
|
@@ -8,13 +8,13 @@ RSpec.describe HPACK::Huffman do
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
it 'should decode' do
|
|
11
|
-
expect(HPACK::Huffman.decode("\xf1\xe3\xc2\xe5\xf2\x3a\x6b\xa0\xab\x90\xf4\xff".b)).to eq 'www.example.com'
|
|
12
|
-
expect(HPACK::Huffman.decode("\xa8\xeb\x10\x64\x9c\xbf".b)).to eq 'no-cache'
|
|
11
|
+
expect(HPACK::Huffman.decode(IO::Buffer.for("\xf1\xe3\xc2\xe5\xf2\x3a\x6b\xa0\xab\x90\xf4\xff".b), 0, 12)).to eq 'www.example.com'
|
|
12
|
+
expect(HPACK::Huffman.decode(IO::Buffer.for("\xa8\xeb\x10\x64\x9c\xbf".b), 0, 6)).to eq 'no-cache'
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it 'should not decode' do
|
|
16
|
-
expect { HPACK::Huffman.decode("\xff\xff\xff\xff".b) }.to raise_error HPACK::Error::HuffmanDecodeError
|
|
17
|
-
expect { HPACK::Huffman.decode("\xf8\xff".b) }.to raise_error HPACK::Error::HuffmanDecodeError
|
|
16
|
+
expect { HPACK::Huffman.decode(IO::Buffer.for("\xff\xff\xff\xff".b), 0, 4) }.to raise_error HPACK::Error::HuffmanDecodeError
|
|
17
|
+
expect { HPACK::Huffman.decode(IO::Buffer.for("\xf8\xff".b), 0, 2) }.to raise_error HPACK::Error::HuffmanDecodeError
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
end
|