http-2-next 0.5.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/http/2/next/base64.rb +37 -0
- data/lib/http/2/next/emitter.rb +1 -1
- data/lib/http/2/next/error.rb +3 -0
- data/lib/http/2/next/extensions.rb +0 -16
- data/lib/http/2/next/framer.rb +2 -6
- data/lib/http/2/next/header/compressor.rb +1 -1
- data/lib/http/2/next/header/decompressor.rb +2 -2
- data/lib/http/2/next/header/encoding_context.rb +1 -3
- data/lib/http/2/next/header/huffman.rb +2 -2
- data/lib/http/2/next/server.rb +0 -1
- data/lib/http/2/next/stream.rb +4 -5
- data/lib/http/2/next/version.rb +1 -1
- data/lib/http/2/next.rb +1 -0
- data/sig/connection.rbs +26 -3
- data/sig/error.rbs +33 -0
- metadata +12 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 910d4e858a63a1b882621dbf2951f2f8a20c29be458de15c9633b451594b797a
|
4
|
+
data.tar.gz: a2ab88e4f38a97320f0d338c149485ee5976645fccd110bd839ba96d6f59432f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72ca980c5aa292e4e92cdf625f8769c77a2a12a9452736a254c668f55cfcdcdcde493db0d8e760eb7d4c1981aadbcdb08f0f48970b8453b3a59dbb5c9ef2a614
|
7
|
+
data.tar.gz: 6875ba9d1136b4c146e89c1b5dad811e4225adb03f99340b09dab0a54f7eeee4aab04596e9bed9f1d68de6b2770aa1548a662d4c9969356612ede4c5d48c2864
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# HTTP-2-Next
|
2
2
|
|
3
3
|
[](http://rubygems.org/gems/http-2-next)
|
4
|
-
[](https://gitlab.com/os85/http-2-next/commits/master)
|
5
|
+
[](https://os85.gitlab.io/http-2-next/coverage/#_AllFiles)
|
6
6
|
|
7
7
|
**Attention!** This is a fork of the [http-2](https://github.com/igrigorik/http-2) gem.
|
8
8
|
|
@@ -265,7 +265,7 @@ conn.on(:stream) do |stream|
|
|
265
265
|
# split response between multiple DATA frames
|
266
266
|
stream.data(response_chunk, end_stream: false)
|
267
267
|
stream.data(last_chunk)
|
268
|
-
|
268
|
+
|
269
269
|
# now send the previously promised data
|
270
270
|
push_stream.data(push_data)
|
271
271
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
if RUBY_VERSION < "3.3.0"
|
4
|
+
require "base64"
|
5
|
+
elsif !defined?(Base64)
|
6
|
+
module HTTP2Next
|
7
|
+
# require "base64" will not be a default gem after ruby 3.4.0
|
8
|
+
module Base64
|
9
|
+
module_function
|
10
|
+
|
11
|
+
def encode64(bin)
|
12
|
+
[bin].pack("m")
|
13
|
+
end
|
14
|
+
|
15
|
+
def decode64(str)
|
16
|
+
str.unpack1("m")
|
17
|
+
end
|
18
|
+
|
19
|
+
def urlsafe_encode64(bin, padding: true)
|
20
|
+
str = strict_encode64(bin)
|
21
|
+
str.chomp!("==") or str.chomp!("=") unless padding
|
22
|
+
str.tr!("+/", "-_")
|
23
|
+
str
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def urlsafe_decode64(str)
|
28
|
+
if !str.end_with?("=") && str.length % 4 != 0
|
29
|
+
str = str.ljust((str.length + 3) & ~3, "=")
|
30
|
+
str.tr!("-_", "+/")
|
31
|
+
else
|
32
|
+
str = str.tr("-_", "+/")
|
33
|
+
end
|
34
|
+
strict_decode64(str)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/http/2/next/emitter.rb
CHANGED
@@ -10,7 +10,7 @@ module HTTP2Next
|
|
10
10
|
# @param event [Symbol]
|
11
11
|
# @param block [Proc] callback function
|
12
12
|
def on(event, &block)
|
13
|
-
raise ArgumentError, "must provide callback" unless
|
13
|
+
raise ArgumentError, "must provide callback" unless block
|
14
14
|
|
15
15
|
listeners(event.to_sym).push block
|
16
16
|
end
|
data/lib/http/2/next/error.rb
CHANGED
@@ -4,6 +4,7 @@ module HTTP2Next
|
|
4
4
|
# Stream, connection, and compressor exceptions.
|
5
5
|
module Error
|
6
6
|
@types = {}
|
7
|
+
|
7
8
|
class << self
|
8
9
|
attr_reader :types
|
9
10
|
end
|
@@ -60,5 +61,7 @@ module HTTP2Next
|
|
60
61
|
class StreamLimitExceeded < Error; end
|
61
62
|
|
62
63
|
class FrameSizeError < Error; end
|
64
|
+
|
65
|
+
@types.freeze
|
63
66
|
end
|
64
67
|
end
|
@@ -1,16 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module HTTP2Next
|
4
|
-
module RegexpExtensions
|
5
|
-
unless Regexp.method_defined?(:match?)
|
6
|
-
refine Regexp do
|
7
|
-
def match?(*args)
|
8
|
-
!match(*args).nil?
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
4
|
module StringExtensions
|
15
5
|
refine String do
|
16
6
|
def read(n)
|
@@ -29,12 +19,6 @@ module HTTP2Next
|
|
29
19
|
def shift_byte
|
30
20
|
read(1).ord
|
31
21
|
end
|
32
|
-
|
33
|
-
unless String.method_defined?(:unpack1)
|
34
|
-
def unpack1(format)
|
35
|
-
unpack(format).first
|
36
|
-
end
|
37
|
-
end
|
38
22
|
end
|
39
23
|
end
|
40
24
|
end
|
data/lib/http/2/next/framer.rb
CHANGED
@@ -325,7 +325,7 @@ module HTTP2Next
|
|
325
325
|
# Padding: Padding octets that contain no application semantic value.
|
326
326
|
# Padding octets MUST be set to zero when sending and ignored when
|
327
327
|
# receiving.
|
328
|
-
bytes << "\0" * padlen
|
328
|
+
bytes << ("\0" * padlen)
|
329
329
|
end
|
330
330
|
|
331
331
|
frame[:length] = length
|
@@ -368,7 +368,7 @@ module HTTP2Next
|
|
368
368
|
end
|
369
369
|
|
370
370
|
case frame[:type]
|
371
|
-
when :data
|
371
|
+
when :data, :ping, :continuation
|
372
372
|
frame[:payload] = payload.read(frame[:length])
|
373
373
|
when :headers
|
374
374
|
if frame[:flags].include? :priority
|
@@ -414,8 +414,6 @@ module HTTP2Next
|
|
414
414
|
when :push_promise
|
415
415
|
frame[:promise_stream] = payload.read_uint32 & RBIT
|
416
416
|
frame[:payload] = payload.read(frame[:length])
|
417
|
-
when :ping
|
418
|
-
frame[:payload] = payload.read(frame[:length])
|
419
417
|
when :goaway
|
420
418
|
frame[:last_stream] = payload.read_uint32 & RBIT
|
421
419
|
frame[:error] = unpack_error payload.read_uint32
|
@@ -428,8 +426,6 @@ module HTTP2Next
|
|
428
426
|
end
|
429
427
|
|
430
428
|
frame[:increment] = payload.read_uint32 & RBIT
|
431
|
-
when :continuation
|
432
|
-
frame[:payload] = payload.read(frame[:length])
|
433
429
|
when :altsvc
|
434
430
|
frame[:max_age], frame[:port] = payload.read(6).unpack(UINT32 + UINT16)
|
435
431
|
|
@@ -30,8 +30,8 @@ module HTTP2Next
|
|
30
30
|
# @param n [Integer] number of available bits
|
31
31
|
# @return [Integer]
|
32
32
|
def integer(buf, n)
|
33
|
-
limit = 2**n - 1
|
34
|
-
i =
|
33
|
+
limit = (2**n) - 1
|
34
|
+
i = n.zero? ? 0 : (buf.shift_byte & limit)
|
35
35
|
|
36
36
|
m = 0
|
37
37
|
if i == limit
|
@@ -8,8 +8,6 @@ module HTTP2Next
|
|
8
8
|
class EncodingContext
|
9
9
|
include Error
|
10
10
|
|
11
|
-
using RegexpExtensions
|
12
|
-
|
13
11
|
UPPER = /[[:upper:]]/.freeze
|
14
12
|
|
15
13
|
# @private
|
@@ -81,7 +79,7 @@ module HTTP2Next
|
|
81
79
|
|
82
80
|
STATIC_TABLE_BY_FIELD = STATIC_TABLE
|
83
81
|
.each_with_object({})
|
84
|
-
.
|
82
|
+
.with_index { |((field, value), hs), idx| (hs[field] ||= []) << [idx, value] }
|
85
83
|
.each { |pair| pair.each(&:freeze).freeze }.freeze
|
86
84
|
|
87
85
|
STATIC_TABLE_SIZE = STATIC_TABLE.size
|
@@ -25,7 +25,7 @@ module HTTP2Next
|
|
25
25
|
# @return [String] binary string
|
26
26
|
def encode(str)
|
27
27
|
bitstring = str.each_byte.map { |chr| ENCODE_TABLE[chr] }.join
|
28
|
-
bitstring << "1" * ((8 - bitstring.size) % 8)
|
28
|
+
bitstring << ("1" * ((8 - bitstring.size) % 8))
|
29
29
|
[bitstring].pack("B*")
|
30
30
|
end
|
31
31
|
|
@@ -40,7 +40,7 @@ module HTTP2Next
|
|
40
40
|
|
41
41
|
mask = (1 << BITS_AT_ONCE) - 1
|
42
42
|
buf.each_byte do |chr|
|
43
|
-
(8 / BITS_AT_ONCE - 1).downto(0) do |shift|
|
43
|
+
((8 / BITS_AT_ONCE) - 1).downto(0) do |shift|
|
44
44
|
branch = (chr >> (shift * BITS_AT_ONCE)) & mask
|
45
45
|
# MACHINE[state] = [final, [transitions]]
|
46
46
|
# [final] unfinished bits so far are prefix of the EOS code.
|
data/lib/http/2/next/server.rb
CHANGED
data/lib/http/2/next/stream.rb
CHANGED
@@ -129,10 +129,9 @@ module HTTP2Next
|
|
129
129
|
@_status_code ||= frame[:status]
|
130
130
|
@_content_length ||= frame[:content_length]
|
131
131
|
@_trailers ||= frame[:trailer]
|
132
|
-
if @_waiting_on_trailers
|
133
|
-
|
134
|
-
|
135
|
-
(!@_status_code || @_status_code >= 200)
|
132
|
+
if @_waiting_on_trailers ||
|
133
|
+
(@received_data &&
|
134
|
+
(!@_status_code || @_status_code >= 200))
|
136
135
|
|
137
136
|
# An endpoint that receives a HEADERS frame without the END_STREAM flag set after receiving a final
|
138
137
|
# (non-informational) status code MUST treat the corresponding request or response as malformed.
|
@@ -225,7 +224,7 @@ module HTTP2Next
|
|
225
224
|
end
|
226
225
|
|
227
226
|
def promise(headers, end_headers: true, &block)
|
228
|
-
raise ArgumentError, "must provide callback" unless
|
227
|
+
raise ArgumentError, "must provide callback" unless block
|
229
228
|
|
230
229
|
flags = end_headers ? [:end_headers] : []
|
231
230
|
emit(:promise, self, headers, flags, &block)
|
data/lib/http/2/next/version.rb
CHANGED
data/lib/http/2/next.rb
CHANGED
data/sig/connection.rbs
CHANGED
@@ -21,6 +21,29 @@ module HTTP2Next
|
|
21
21
|
|
22
22
|
attr_writer max_streams: Integer?
|
23
23
|
|
24
|
+
@stream_id: Integer
|
25
|
+
@active_stream_count: Integer
|
26
|
+
@last_activated_stream: Integer
|
27
|
+
@last_stream_id: Integer
|
28
|
+
|
29
|
+
@streams: Hash[Integer, Stream]
|
30
|
+
@streams_recently_closed: Hash[Integer, Stream]
|
31
|
+
|
32
|
+
@framer: Framer
|
33
|
+
|
34
|
+
@local_window_limit: Integer
|
35
|
+
@remote_window_limit: Integer
|
36
|
+
|
37
|
+
@compressor: Header::Compressor
|
38
|
+
@decompressor: Header::Decompressor
|
39
|
+
@error: Symbol?
|
40
|
+
|
41
|
+
@recv_buffer: String
|
42
|
+
@continuation: Array[frame]
|
43
|
+
|
44
|
+
@closed_since: Float?
|
45
|
+
@received_frame: bool
|
46
|
+
|
24
47
|
def closed?: () -> bool
|
25
48
|
|
26
49
|
def new_stream: (**untyped) -> Stream
|
@@ -37,9 +60,9 @@ module HTTP2Next
|
|
37
60
|
def receive: (string data) -> void
|
38
61
|
alias << receive
|
39
62
|
|
40
|
-
|
63
|
+
def initialize: (?settings_hash) -> void
|
41
64
|
|
42
|
-
|
65
|
+
private
|
43
66
|
|
44
67
|
def send: (frame) -> void
|
45
68
|
|
@@ -67,6 +90,6 @@ module HTTP2Next
|
|
67
90
|
|
68
91
|
def _verify_pseudo_headers: (frame, Array[String]) -> void
|
69
92
|
|
70
|
-
def connection_error: (?Symbol error, ?msg: String
|
93
|
+
def connection_error: (?Symbol error, ?msg: String?, ?e: StandardError?) -> void
|
71
94
|
end
|
72
95
|
end
|
data/sig/error.rbs
CHANGED
@@ -1,2 +1,35 @@
|
|
1
1
|
module HTTP2Next
|
2
|
+
module Error
|
3
|
+
def self?.types: () -> Hash[Symbol, singleton(Error)]
|
4
|
+
|
5
|
+
class Error < StandardError
|
6
|
+
end
|
7
|
+
|
8
|
+
class HandshakeError < Error
|
9
|
+
end
|
10
|
+
|
11
|
+
class ProtocolError < Error
|
12
|
+
end
|
13
|
+
|
14
|
+
class CompressionError < ProtocolError
|
15
|
+
end
|
16
|
+
|
17
|
+
class FlowControlError < ProtocolError
|
18
|
+
end
|
19
|
+
|
20
|
+
class InternalError < ProtocolError
|
21
|
+
end
|
22
|
+
|
23
|
+
class StreamClosed < Error
|
24
|
+
end
|
25
|
+
|
26
|
+
class ConnectionClosed < Error
|
27
|
+
end
|
28
|
+
|
29
|
+
class StreamLimitExceeded < Error
|
30
|
+
end
|
31
|
+
|
32
|
+
class FrameSizeError < Error
|
33
|
+
end
|
34
|
+
end
|
2
35
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http-2-next
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tiago Cardoso
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2023-10-03 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: Pure-ruby HTTP 2.0 protocol implementation
|
16
16
|
email:
|
@@ -21,6 +21,7 @@ extra_rdoc_files: []
|
|
21
21
|
files:
|
22
22
|
- README.md
|
23
23
|
- lib/http/2/next.rb
|
24
|
+
- lib/http/2/next/base64.rb
|
24
25
|
- lib/http/2/next/client.rb
|
25
26
|
- lib/http/2/next/connection.rb
|
26
27
|
- lib/http/2/next/emitter.rb
|
@@ -53,10 +54,15 @@ files:
|
|
53
54
|
- sig/next.rbs
|
54
55
|
- sig/server.rbs
|
55
56
|
- sig/stream.rbs
|
56
|
-
homepage: https://gitlab.com/
|
57
|
+
homepage: https://gitlab.com/os85/http-2-next
|
57
58
|
licenses:
|
58
59
|
- MIT
|
59
|
-
metadata:
|
60
|
+
metadata:
|
61
|
+
bug_tracker_uri: https://gitlab.com/os85/http-2-next/issues
|
62
|
+
changelog_uri: https://gitlab.com/os85/http-2-next/-/blob/master/CHANGELOG.md
|
63
|
+
source_code_uri: https://gitlab.com/os85/http-2-next
|
64
|
+
homepage_uri: https://gitlab.com/os85/http-2-next
|
65
|
+
rubygems_mfa_required: 'true'
|
60
66
|
post_install_message:
|
61
67
|
rdoc_options: []
|
62
68
|
require_paths:
|
@@ -65,14 +71,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
71
|
requirements:
|
66
72
|
- - ">="
|
67
73
|
- !ruby/object:Gem::Version
|
68
|
-
version: 2.
|
74
|
+
version: 2.7.0
|
69
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
76
|
requirements:
|
71
77
|
- - ">="
|
72
78
|
- !ruby/object:Gem::Version
|
73
79
|
version: '0'
|
74
80
|
requirements: []
|
75
|
-
rubygems_version: 3.
|
81
|
+
rubygems_version: 3.4.10
|
76
82
|
signing_key:
|
77
83
|
specification_version: 4
|
78
84
|
summary: Pure-ruby HTTP 2.0 protocol implementation
|