protocol-http2 0.14.2 → 0.15.1
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
- checksums.yaml.gz.sig +0 -0
- data/lib/protocol/http2/client.rb +4 -23
- data/lib/protocol/http2/connection.rb +33 -52
- data/lib/protocol/http2/continuation_frame.rb +9 -20
- data/lib/protocol/http2/data_frame.rb +5 -21
- data/lib/protocol/http2/dependency.rb +9 -24
- data/lib/protocol/http2/error.rb +10 -25
- data/lib/protocol/http2/flow_controlled.rb +5 -19
- data/lib/protocol/http2/frame.rb +23 -28
- data/lib/protocol/http2/framer.rb +8 -24
- data/lib/protocol/http2/goaway_frame.rb +4 -19
- data/lib/protocol/http2/headers_frame.rb +5 -20
- data/lib/protocol/http2/padded.rb +10 -24
- data/lib/protocol/http2/ping_frame.rb +12 -19
- data/lib/protocol/http2/priority_frame.rb +4 -23
- data/lib/protocol/http2/push_promise_frame.rb +4 -19
- data/lib/protocol/http2/reset_stream_frame.rb +4 -19
- data/lib/protocol/http2/server.rb +5 -20
- data/lib/protocol/http2/settings_frame.rb +22 -34
- data/lib/protocol/http2/stream.rb +11 -23
- data/lib/protocol/http2/version.rb +5 -20
- data/lib/protocol/http2/window_update_frame.rb +23 -26
- data/lib/protocol/http2.rb +4 -19
- data/license.md +24 -0
- data/readme.md +98 -0
- data.tar.gz.sig +0 -0
- metadata +44 -10
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 89961e568533a95a580a7eaa79c9d519a9467016b819739f2868385fb2cb2d2f
|
|
4
|
+
data.tar.gz: 185af0c2c4d5fb02077daf4b5ac1131abb013842f151e24f5b3b0f2b2aef0a60
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d0c3233cb4842658ad1e013c004fe043d0dc952eb3404bd91acfe6471c6b686da6bec1f81923202ed725713ad6f4cc603a99418eaf565ad317bd301756e551bc
|
|
7
|
+
data.tar.gz: 72f5fd86a460e9c71cb5d7587c165c7ffe1a8be4f44afd99010e04f7dc18fc85011d5ed723a40a3c3d84831f45acdcfe6e093270938e1dd7066e5acde74dbe9a
|
checksums.yaml.gz.sig
ADDED
|
Binary file
|
|
@@ -1,22 +1,7 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
# furnished to do so, subject to the following conditions:
|
|
9
|
-
#
|
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
|
11
|
-
# all copies or substantial portions of the Software.
|
|
12
|
-
#
|
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
-
# THE SOFTWARE.
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
|
20
5
|
|
|
21
6
|
require_relative 'connection'
|
|
22
7
|
|
|
@@ -68,10 +53,6 @@ module Protocol
|
|
|
68
53
|
# This is almost certainly invalid:
|
|
69
54
|
promised_stream, request_headers = stream.receive_push_promise(frame)
|
|
70
55
|
|
|
71
|
-
if stream.closed?
|
|
72
|
-
@streams.delete(stream.id)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
56
|
return promised_stream, request_headers
|
|
76
57
|
end
|
|
77
58
|
end
|
|
@@ -1,22 +1,8 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
# furnished to do so, subject to the following conditions:
|
|
9
|
-
#
|
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
|
11
|
-
# all copies or substantial portions of the Software.
|
|
12
|
-
#
|
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
-
# THE SOFTWARE.
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
|
5
|
+
# Copyright, 2023, by Marco Concetto Rudilosso.
|
|
20
6
|
|
|
21
7
|
require_relative 'framer'
|
|
22
8
|
require_relative 'dependency'
|
|
@@ -55,7 +41,7 @@ module Protocol
|
|
|
55
41
|
@decoder = HPACK::Context.new
|
|
56
42
|
@encoder = HPACK::Context.new
|
|
57
43
|
|
|
58
|
-
@local_window = LocalWindow.new
|
|
44
|
+
@local_window = LocalWindow.new()
|
|
59
45
|
@remote_window = Window.new
|
|
60
46
|
end
|
|
61
47
|
|
|
@@ -77,7 +63,7 @@ module Protocol
|
|
|
77
63
|
end
|
|
78
64
|
|
|
79
65
|
def maximum_concurrent_streams
|
|
80
|
-
|
|
66
|
+
@local_settings.maximum_concurrent_streams
|
|
81
67
|
end
|
|
82
68
|
|
|
83
69
|
attr :framer
|
|
@@ -115,6 +101,7 @@ module Protocol
|
|
|
115
101
|
@streams.each_value{|stream| stream.close(error)}
|
|
116
102
|
@streams.clear
|
|
117
103
|
|
|
104
|
+
ensure
|
|
118
105
|
if @framer
|
|
119
106
|
@framer.close
|
|
120
107
|
@framer = nil
|
|
@@ -301,9 +288,10 @@ module Protocol
|
|
|
301
288
|
|
|
302
289
|
def receive_ping(frame)
|
|
303
290
|
if @state != :closed
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
291
|
+
# This is handled in `read_payload`:
|
|
292
|
+
# if frame.stream_id != 0
|
|
293
|
+
# raise ProtocolError, "Ping received for non-zero stream!"
|
|
294
|
+
# end
|
|
307
295
|
|
|
308
296
|
unless frame.acknowledgement?
|
|
309
297
|
reply = frame.acknowledge
|
|
@@ -327,7 +315,7 @@ module Protocol
|
|
|
327
315
|
end
|
|
328
316
|
end
|
|
329
317
|
|
|
330
|
-
def valid_remote_stream_id?
|
|
318
|
+
def valid_remote_stream_id?(stream_id)
|
|
331
319
|
false
|
|
332
320
|
end
|
|
333
321
|
|
|
@@ -352,6 +340,10 @@ module Protocol
|
|
|
352
340
|
# On the client side, we create requests.
|
|
353
341
|
# @return [Stream] the created stream.
|
|
354
342
|
def create_stream(id = next_stream_id, &block)
|
|
343
|
+
if @streams.key?(id)
|
|
344
|
+
raise ProtocolError, "Cannot create stream with id #{id}, already exists!"
|
|
345
|
+
end
|
|
346
|
+
|
|
355
347
|
if block_given?
|
|
356
348
|
return yield(self, id)
|
|
357
349
|
else
|
|
@@ -396,24 +388,6 @@ module Protocol
|
|
|
396
388
|
write_frame(frame)
|
|
397
389
|
end
|
|
398
390
|
|
|
399
|
-
def idle_stream_id?(id)
|
|
400
|
-
if id.even?
|
|
401
|
-
# Server-initiated streams are even.
|
|
402
|
-
if @local_stream_id.even?
|
|
403
|
-
id >= @local_stream_id
|
|
404
|
-
else
|
|
405
|
-
id > @remote_stream_id
|
|
406
|
-
end
|
|
407
|
-
elsif id.odd?
|
|
408
|
-
# Client-initiated streams are odd.
|
|
409
|
-
if @local_stream_id.odd?
|
|
410
|
-
id >= @local_stream_id
|
|
411
|
-
else
|
|
412
|
-
id > @remote_stream_id
|
|
413
|
-
end
|
|
414
|
-
end
|
|
415
|
-
end
|
|
416
|
-
|
|
417
391
|
# Sets the priority for an incoming stream.
|
|
418
392
|
def receive_priority(frame)
|
|
419
393
|
if dependency = @dependencies[frame.stream_id]
|
|
@@ -435,27 +409,34 @@ module Protocol
|
|
|
435
409
|
id.even?
|
|
436
410
|
end
|
|
437
411
|
|
|
438
|
-
def
|
|
439
|
-
if id.
|
|
440
|
-
# The connection "stream id" can never be closed:
|
|
441
|
-
false
|
|
442
|
-
elsif id.even?
|
|
412
|
+
def idle_stream_id?(id)
|
|
413
|
+
if id.even?
|
|
443
414
|
# Server-initiated streams are even.
|
|
444
415
|
if @local_stream_id.even?
|
|
445
|
-
id
|
|
416
|
+
id >= @local_stream_id
|
|
446
417
|
else
|
|
447
|
-
id
|
|
418
|
+
id > @remote_stream_id
|
|
448
419
|
end
|
|
449
420
|
elsif id.odd?
|
|
450
421
|
# Client-initiated streams are odd.
|
|
451
422
|
if @local_stream_id.odd?
|
|
452
|
-
id
|
|
423
|
+
id >= @local_stream_id
|
|
453
424
|
else
|
|
454
|
-
id
|
|
425
|
+
id > @remote_stream_id
|
|
455
426
|
end
|
|
456
427
|
end
|
|
457
428
|
end
|
|
458
429
|
|
|
430
|
+
# This is only valid if the stream doesn't exist in `@streams`.
|
|
431
|
+
def closed_stream_id?(id)
|
|
432
|
+
if id.zero?
|
|
433
|
+
# The connection "stream id" can never be closed:
|
|
434
|
+
false
|
|
435
|
+
else
|
|
436
|
+
!idle_stream_id?(id)
|
|
437
|
+
end
|
|
438
|
+
end
|
|
439
|
+
|
|
459
440
|
def receive_reset_stream(frame)
|
|
460
441
|
if frame.connection?
|
|
461
442
|
raise ProtocolError, "Cannot reset connection!"
|
|
@@ -1,22 +1,7 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
# furnished to do so, subject to the following conditions:
|
|
9
|
-
#
|
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
|
11
|
-
# all copies or substantial portions of the Software.
|
|
12
|
-
#
|
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
-
# THE SOFTWARE.
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
|
20
5
|
|
|
21
6
|
require_relative 'frame'
|
|
22
7
|
|
|
@@ -29,6 +14,10 @@ module Protocol
|
|
|
29
14
|
@continuation = nil
|
|
30
15
|
end
|
|
31
16
|
|
|
17
|
+
def continued?
|
|
18
|
+
!!@continuation
|
|
19
|
+
end
|
|
20
|
+
|
|
32
21
|
def end_headers?
|
|
33
22
|
flag_set?(END_HEADERS)
|
|
34
23
|
end
|
|
@@ -112,7 +101,7 @@ module Protocol
|
|
|
112
101
|
end
|
|
113
102
|
|
|
114
103
|
def inspect
|
|
115
|
-
"\#<#{self.class} stream_id=#{@stream_id} flags=#{@flags}
|
|
104
|
+
"\#<#{self.class} stream_id=#{@stream_id} flags=#{@flags} length=#{@length || 0}b>"
|
|
116
105
|
end
|
|
117
106
|
end
|
|
118
107
|
end
|
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
# of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
# in the Software without restriction, including without limitation the rights
|
|
7
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
# furnished to do so, subject to the following conditions:
|
|
10
|
-
#
|
|
11
|
-
# The above copyright notice and this permission notice shall be included in
|
|
12
|
-
# all copies or substantial portions of the Software.
|
|
13
|
-
#
|
|
14
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
-
# THE SOFTWARE.
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
|
21
5
|
|
|
22
6
|
require_relative 'frame'
|
|
23
7
|
require_relative 'padded'
|
|
@@ -59,7 +43,7 @@ module Protocol
|
|
|
59
43
|
end
|
|
60
44
|
|
|
61
45
|
def inspect
|
|
62
|
-
"\#<#{self.class} stream_id=#{@stream_id} flags=#{@flags} #{@length}b>"
|
|
46
|
+
"\#<#{self.class} stream_id=#{@stream_id} flags=#{@flags} #{@length || 0}b>"
|
|
63
47
|
end
|
|
64
48
|
end
|
|
65
49
|
end
|
|
@@ -1,22 +1,7 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
# furnished to do so, subject to the following conditions:
|
|
9
|
-
#
|
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
|
11
|
-
# all copies or substantial portions of the Software.
|
|
12
|
-
#
|
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
-
# THE SOFTWARE.
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2020-2023, by Samuel Williams.
|
|
20
5
|
|
|
21
6
|
module Protocol
|
|
22
7
|
module HTTP2
|
|
@@ -185,7 +170,7 @@ module Protocol
|
|
|
185
170
|
end
|
|
186
171
|
|
|
187
172
|
def total_weight
|
|
188
|
-
self.
|
|
173
|
+
self.ordered_children
|
|
189
174
|
|
|
190
175
|
return @total_weight
|
|
191
176
|
end
|
|
@@ -218,14 +203,14 @@ module Protocol
|
|
|
218
203
|
end
|
|
219
204
|
end
|
|
220
205
|
|
|
221
|
-
def
|
|
206
|
+
def inspect
|
|
222
207
|
"\#<#{self.class} id=#{@id} parent id=#{@parent&.id} weight=#{@weight} #{@children&.size || 0} children>"
|
|
223
208
|
end
|
|
224
209
|
|
|
225
|
-
def print_hierarchy(
|
|
226
|
-
|
|
210
|
+
def print_hierarchy(output = $stderr, indent: 0)
|
|
211
|
+
output.puts "#{"\t" * indent}#{self.inspect}"
|
|
227
212
|
@children&.each_value do |child|
|
|
228
|
-
child.print_hierarchy(
|
|
213
|
+
child.print_hierarchy(output, indent: indent+1)
|
|
229
214
|
end
|
|
230
215
|
end
|
|
231
216
|
end
|
data/lib/protocol/http2/error.rb
CHANGED
|
@@ -1,22 +1,7 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
# furnished to do so, subject to the following conditions:
|
|
9
|
-
#
|
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
|
11
|
-
# all copies or substantial portions of the Software.
|
|
12
|
-
#
|
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
-
# THE SOFTWARE.
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
|
20
5
|
|
|
21
6
|
require 'protocol/http/error'
|
|
22
7
|
|
|
@@ -95,12 +80,6 @@ module Protocol
|
|
|
95
80
|
end
|
|
96
81
|
end
|
|
97
82
|
|
|
98
|
-
class HeaderError < StreamClosed
|
|
99
|
-
def initialize(message)
|
|
100
|
-
super(message)
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
|
|
104
83
|
class GoawayError < ProtocolError
|
|
105
84
|
end
|
|
106
85
|
|
|
@@ -111,6 +90,12 @@ module Protocol
|
|
|
111
90
|
end
|
|
112
91
|
end
|
|
113
92
|
|
|
93
|
+
class HeaderError < StreamClosed
|
|
94
|
+
def initialize(message)
|
|
95
|
+
super(message)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
114
99
|
# Raised on invalid flow control frame or command.
|
|
115
100
|
class FlowControlError < ProtocolError
|
|
116
101
|
def initialize(message)
|
|
@@ -1,22 +1,8 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
# furnished to do so, subject to the following conditions:
|
|
9
|
-
#
|
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
|
11
|
-
# all copies or substantial portions of the Software.
|
|
12
|
-
#
|
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
-
# THE SOFTWARE.
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
|
5
|
+
# Copyright, 2019, by Yuta Iwama.
|
|
20
6
|
|
|
21
7
|
require_relative 'window_update_frame'
|
|
22
8
|
|
data/lib/protocol/http2/frame.rb
CHANGED
|
@@ -1,23 +1,8 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
# in the Software without restriction, including without limitation the rights
|
|
7
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
# furnished to do so, subject to the following conditions:
|
|
10
|
-
#
|
|
11
|
-
# The above copyright notice and this permission notice shall be included in
|
|
12
|
-
# all copies or substantial portions of the Software.
|
|
13
|
-
#
|
|
14
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
-
# THE SOFTWARE.
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
|
5
|
+
# Copyright, 2019, by Yuta Iwama.
|
|
21
6
|
|
|
22
7
|
require_relative 'error'
|
|
23
8
|
|
|
@@ -46,12 +31,15 @@ module Protocol
|
|
|
46
31
|
LENGTH_HISHIFT = 16
|
|
47
32
|
LENGTH_LOMASK = 0xFFFF
|
|
48
33
|
|
|
34
|
+
# The base class does not have any specific type index:
|
|
35
|
+
TYPE = nil
|
|
36
|
+
|
|
49
37
|
# @param length [Integer] the length of the payload, or nil if the header has not been read yet.
|
|
50
38
|
def initialize(stream_id = 0, flags = 0, type = self.class::TYPE, length = nil, payload = nil)
|
|
51
|
-
@length = length
|
|
52
|
-
@type = type
|
|
53
|
-
@flags = flags
|
|
54
39
|
@stream_id = stream_id
|
|
40
|
+
@flags = flags
|
|
41
|
+
@type = type
|
|
42
|
+
@length = length
|
|
55
43
|
@payload = payload
|
|
56
44
|
end
|
|
57
45
|
|
|
@@ -94,7 +82,7 @@ module Protocol
|
|
|
94
82
|
@length = payload.bytesize
|
|
95
83
|
|
|
96
84
|
if maximum_size and @length > maximum_size
|
|
97
|
-
raise ProtocolError, "Frame length
|
|
85
|
+
raise ProtocolError, "Frame length bigger than maximum allowed: #{@length} > #{maximum_size}"
|
|
98
86
|
end
|
|
99
87
|
end
|
|
100
88
|
|
|
@@ -127,7 +115,7 @@ module Protocol
|
|
|
127
115
|
# @return [String]
|
|
128
116
|
def header
|
|
129
117
|
unless VALID_LENGTH.include? @length
|
|
130
|
-
raise ProtocolError, "Invalid frame
|
|
118
|
+
raise ProtocolError, "Invalid frame length: #{@length.inspect}"
|
|
131
119
|
end
|
|
132
120
|
|
|
133
121
|
unless VALID_STREAM_ID.include? @stream_id
|
|
@@ -193,8 +181,15 @@ module Protocol
|
|
|
193
181
|
end
|
|
194
182
|
|
|
195
183
|
def write(stream)
|
|
196
|
-
|
|
197
|
-
|
|
184
|
+
# Validate the payload size:
|
|
185
|
+
if @payload.nil?
|
|
186
|
+
if @length != 0
|
|
187
|
+
raise ProtocolError, "Invalid frame length: #{@length} != 0"
|
|
188
|
+
end
|
|
189
|
+
else
|
|
190
|
+
if @length != @payload.bytesize
|
|
191
|
+
raise ProtocolError, "Invalid payload size: #{@length} != #{@payload.bytesize}"
|
|
192
|
+
end
|
|
198
193
|
end
|
|
199
194
|
|
|
200
195
|
self.write_header(stream)
|
|
@@ -206,7 +201,7 @@ module Protocol
|
|
|
206
201
|
end
|
|
207
202
|
|
|
208
203
|
def inspect
|
|
209
|
-
"\#<#{self.class} stream_id=#{@stream_id} flags=#{@flags}
|
|
204
|
+
"\#<#{self.class} stream_id=#{@stream_id} flags=#{@flags} payload=#{self.unpack}>"
|
|
210
205
|
end
|
|
211
206
|
end
|
|
212
207
|
end
|
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
# of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
# in the Software without restriction, including without limitation the rights
|
|
7
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
# furnished to do so, subject to the following conditions:
|
|
10
|
-
#
|
|
11
|
-
# The above copyright notice and this permission notice shall be included in
|
|
12
|
-
# all copies or substantial portions of the Software.
|
|
13
|
-
#
|
|
14
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
-
# THE SOFTWARE.
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
|
21
5
|
|
|
22
6
|
require_relative 'error'
|
|
23
7
|
|
|
@@ -49,7 +33,7 @@ module Protocol
|
|
|
49
33
|
].freeze
|
|
50
34
|
|
|
51
35
|
# Default connection "fast-fail" preamble string as defined by the spec.
|
|
52
|
-
|
|
36
|
+
CONNECTION_PREFACE = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n".freeze
|
|
53
37
|
|
|
54
38
|
class Framer
|
|
55
39
|
def initialize(stream, frames = FRAMES)
|
|
@@ -66,13 +50,13 @@ module Protocol
|
|
|
66
50
|
end
|
|
67
51
|
|
|
68
52
|
def write_connection_preface
|
|
69
|
-
@stream.write(
|
|
53
|
+
@stream.write(CONNECTION_PREFACE)
|
|
70
54
|
end
|
|
71
55
|
|
|
72
56
|
def read_connection_preface
|
|
73
|
-
string = @stream.read(
|
|
57
|
+
string = @stream.read(CONNECTION_PREFACE.bytesize)
|
|
74
58
|
|
|
75
|
-
unless string ==
|
|
59
|
+
unless string == CONNECTION_PREFACE
|
|
76
60
|
raise HandshakeError, "Invalid connection preface: #{string.inspect}"
|
|
77
61
|
end
|
|
78
62
|
|
|
@@ -1,22 +1,7 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
# furnished to do so, subject to the following conditions:
|
|
9
|
-
#
|
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
|
11
|
-
# all copies or substantial portions of the Software.
|
|
12
|
-
#
|
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
-
# THE SOFTWARE.
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
|
20
5
|
|
|
21
6
|
require_relative 'frame'
|
|
22
7
|
|
|
@@ -1,22 +1,7 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
# furnished to do so, subject to the following conditions:
|
|
9
|
-
#
|
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
|
11
|
-
# all copies or substantial portions of the Software.
|
|
12
|
-
#
|
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
-
# THE SOFTWARE.
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
|
20
5
|
|
|
21
6
|
require_relative 'frame'
|
|
22
7
|
require_relative 'padded'
|
|
@@ -83,7 +68,7 @@ module Protocol
|
|
|
83
68
|
end
|
|
84
69
|
|
|
85
70
|
def inspect
|
|
86
|
-
"\#<#{self.class} stream_id=#{@stream_id} flags=#{@flags} #{@length}b>"
|
|
71
|
+
"\#<#{self.class} stream_id=#{@stream_id} flags=#{@flags} #{@length || 0}b>"
|
|
87
72
|
end
|
|
88
73
|
end
|
|
89
74
|
end
|