protocol-http2 0.14.2 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c08e3a01dc017b795d02fbe0c0d40ba55afb475952309edb0e0a76146a9e6f3b
4
- data.tar.gz: c493a5e2bcd50eae781baaa83a7a01224a09227490aeb5e1472a1f2c7f017181
3
+ metadata.gz: 28d53d86975d6aa52e2ea20e36c41fa4e8fff6437ef8b831de001b3d2849609b
4
+ data.tar.gz: 6c13193934a0eea767493757ff70e814d68f66fe68af4a774fb22d707e78437d
5
5
  SHA512:
6
- metadata.gz: 32ddc91c1bcb1396305760e956291cbaa199af6cbd84026c102d0860c0fa852c232cceb1f9561758ea73fa2902ac525045411a9e2dd02297b35643f2349b5993
7
- data.tar.gz: b00bf59cf1e91b5464960b0e6848e67a96653e48a9739985c9c03070c8d66c5d18067d5e9db38c904447ce696d57766493f656c22b35490363cf73d703867306
6
+ metadata.gz: 13bcd265d3eba3c322cdc6a473955a946a219f9d6f0015607a04248392fccadf70d456b42e1fdc455697678f95a87982e95ca7dda1774468f87dfdb16ed09d4e
7
+ data.tar.gz: 1f393c99f5657db925c6ea337ba5190cc722b8e8698d7d30751348b061719c60f905b551a2d60e1d90182a94dae1c2dcbc23eee9c2bf408b46bb0b08faa3799f
checksums.yaml.gz.sig ADDED
Binary file
@@ -1,22 +1,7 @@
1
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
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
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
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.
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
- [@local_settings.maximum_concurrent_streams, @remote_settings.maximum_concurrent_streams].min
66
+ @local_settings.maximum_concurrent_streams
81
67
  end
82
68
 
83
69
  attr :framer
@@ -301,9 +287,10 @@ module Protocol
301
287
 
302
288
  def receive_ping(frame)
303
289
  if @state != :closed
304
- if frame.stream_id != 0
305
- raise ProtocolError, "Ping received for non-zero stream!"
306
- end
290
+ # This is handled in `read_payload`:
291
+ # if frame.stream_id != 0
292
+ # raise ProtocolError, "Ping received for non-zero stream!"
293
+ # end
307
294
 
308
295
  unless frame.acknowledgement?
309
296
  reply = frame.acknowledge
@@ -327,7 +314,7 @@ module Protocol
327
314
  end
328
315
  end
329
316
 
330
- def valid_remote_stream_id?
317
+ def valid_remote_stream_id?(stream_id)
331
318
  false
332
319
  end
333
320
 
@@ -352,6 +339,10 @@ module Protocol
352
339
  # On the client side, we create requests.
353
340
  # @return [Stream] the created stream.
354
341
  def create_stream(id = next_stream_id, &block)
342
+ if @streams.key?(id)
343
+ raise ProtocolError, "Cannot create stream with id #{id}, already exists!"
344
+ end
345
+
355
346
  if block_given?
356
347
  return yield(self, id)
357
348
  else
@@ -396,24 +387,6 @@ module Protocol
396
387
  write_frame(frame)
397
388
  end
398
389
 
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
390
  # Sets the priority for an incoming stream.
418
391
  def receive_priority(frame)
419
392
  if dependency = @dependencies[frame.stream_id]
@@ -435,27 +408,34 @@ module Protocol
435
408
  id.even?
436
409
  end
437
410
 
438
- def closed_stream_id?(id)
439
- if id.zero?
440
- # The connection "stream id" can never be closed:
441
- false
442
- elsif id.even?
411
+ def idle_stream_id?(id)
412
+ if id.even?
443
413
  # Server-initiated streams are even.
444
414
  if @local_stream_id.even?
445
- id < @local_stream_id
415
+ id >= @local_stream_id
446
416
  else
447
- id <= @remote_stream_id
417
+ id > @remote_stream_id
448
418
  end
449
419
  elsif id.odd?
450
420
  # Client-initiated streams are odd.
451
421
  if @local_stream_id.odd?
452
- id < @local_stream_id
422
+ id >= @local_stream_id
453
423
  else
454
- id <= @remote_stream_id
424
+ id > @remote_stream_id
455
425
  end
456
426
  end
457
427
  end
458
428
 
429
+ # This is only valid if the stream doesn't exist in `@streams`.
430
+ def closed_stream_id?(id)
431
+ if id.zero?
432
+ # The connection "stream id" can never be closed:
433
+ false
434
+ else
435
+ !idle_stream_id?(id)
436
+ end
437
+ end
438
+
459
439
  def receive_reset_stream(frame)
460
440
  if frame.connection?
461
441
  raise ProtocolError, "Cannot reset connection!"
@@ -1,22 +1,7 @@
1
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
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} #{@length}b>"
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
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- # Copyright, 2013, by Ilya Grigorik.
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
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
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
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.orderd_children
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 to_s
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(buffer, indent: 0)
226
- buffer.puts "#{" " * indent}#{self}"
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(buffer, indent: indent+1)
213
+ child.print_hierarchy(output, indent: indent+1)
229
214
  end
230
215
  end
231
216
  end
@@ -1,22 +1,7 @@
1
- # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
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
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
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.
5
+ # Copyright, 2019, by Yuta Iwama.
20
6
 
21
7
  require_relative 'window_update_frame'
22
8
 
@@ -1,23 +1,8 @@
1
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- # Copyright, 2013, by Ilya Grigorik.
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
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.
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 #{@length} bigger than maximum allowed: #{maximum_size}"
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 size: #{@length.inspect}"
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
- if @payload and @length != @payload.bytesize
197
- raise ProtocolError, "Invalid payload size: #{@length} != #{@payload.bytesize}"
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} #{self.unpack}>"
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
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- # Copyright, 2013, by Ilya Grigorik.
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
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
- CONNECTION_PREFACE_MAGIC = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n".freeze
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(CONNECTION_PREFACE_MAGIC)
53
+ @stream.write(CONNECTION_PREFACE)
70
54
  end
71
55
 
72
56
  def read_connection_preface
73
- string = @stream.read(CONNECTION_PREFACE_MAGIC.bytesize)
57
+ string = @stream.read(CONNECTION_PREFACE.bytesize)
74
58
 
75
- unless string == CONNECTION_PREFACE_MAGIC
59
+ unless string == CONNECTION_PREFACE
76
60
  raise HandshakeError, "Invalid connection preface: #{string.inspect}"
77
61
  end
78
62
 
@@ -1,22 +1,7 @@
1
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
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
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
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
@@ -1,23 +1,7 @@
1
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- # Copyright, 2013, by Ilya Grigorik.
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
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
 
@@ -63,7 +47,7 @@ module Protocol
63
47
  def unpack
64
48
  if padded?
65
49
  padding_size = @payload[0].ord
66
- data_size = (@payload.bytesize - 1) - padding_size
50
+ data_size = @payload.bytesize - padding_size
67
51
 
68
52
  if data_size < 0
69
53
  raise ProtocolError, "Invalid padding length: #{padding_size}"