protocol-http2 0.11.1 → 0.11.2

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: 06d77286478b994ec73dfa49f0b6326b06fa29618477b50a771222e8eda19612
4
- data.tar.gz: c20e0dcb47e7999ea0cb6f60328c0acb309881c0645b4963ce769548923959af
3
+ metadata.gz: 680080c7a69a5ed1afb2520f43a7e6335b0470cb972aa91cab6be7a3c2358240
4
+ data.tar.gz: f7b3bad2356b04793de349d2c299fb64e855f243120a186dd2dc01906052e08a
5
5
  SHA512:
6
- metadata.gz: b9dfe13295aa56fb40269d57ae2b70d02ed69017253013f23cb7a6595827465425d330757e2bfe47f8a0f0fd5dceadfd4e9ed0f6dd245e9d6158be3346e3219e
7
- data.tar.gz: d1f5af9a4d37c4c1a9b892db33e7979f710b4988da9f6a7e675805cc40bd22d67086c5cc1da8333521035707c274ba0f89520ddbf06c824531da672b5c4ce79f
6
+ metadata.gz: 042dd35ecdf9b6b81fa4dcdd3e788346cc0389eec765783c587bc7cebdf74a7204dfc31ef8e2bbe644e5a417ea29dae4fb4f4134aac6c37ef7bb374d0229d3a3
7
+ data.tar.gz: 45397ddea195960f4a1c253d5cac0028e17b2bfa3fbff6a9aa157f2244bbc5894d610346b98a4a0affe0921d0c627bc3d5db0c438c0a2bec792ea993365da870
@@ -27,6 +27,14 @@ module Protocol
27
27
  super(framer, 1)
28
28
  end
29
29
 
30
+ def local_stream_id?(id)
31
+ id.odd?
32
+ end
33
+
34
+ def remote_stream_id?(id)
35
+ id.even?
36
+ end
37
+
30
38
  def valid_remote_stream_id?(stream_id)
31
39
  stream_id.even?
32
40
  end
@@ -41,6 +41,7 @@ module Protocol
41
41
  @dependencies = {0 => @dependency}
42
42
 
43
43
  @framer = framer
44
+ # The next stream id to use:
44
45
  @local_stream_id = local_stream_id
45
46
  @remote_stream_id = 0
46
47
 
@@ -420,9 +421,42 @@ module Protocol
420
421
  raise ProtocolError, "Unable to receive push promise!"
421
422
  end
422
423
 
424
+ def client_stream_id?(id)
425
+ id.odd?
426
+ end
427
+
428
+ def server_stream_id?(id)
429
+ id.even?
430
+ end
431
+
432
+ def closed_stream_id?(id)
433
+ if id.zero?
434
+ # The connection "stream id" can never be closed:
435
+ false
436
+ elsif id.even?
437
+ # Server-initiated streams are even.
438
+ if @local_stream_id.even?
439
+ id < @local_stream_id
440
+ else
441
+ id < @remote_stream_id
442
+ end
443
+ elsif id.odd?
444
+ # Client-initiated streams are odd.
445
+ if @local_stream_id.odd?
446
+ id < @local_stream_id
447
+ else
448
+ id < @remote_stream_id
449
+ end
450
+ end
451
+ end
452
+
423
453
  def receive_reset_stream(frame)
424
- if stream = @streams[frame.stream_id]
454
+ if frame.connection?
455
+ raise ProtocolError, "Cannot reset connection!"
456
+ elsif stream = @streams[frame.stream_id]
425
457
  stream.receive_reset_stream(frame)
458
+ elsif closed_stream_id?(frame.stream_id)
459
+ # Ignore.
426
460
  else
427
461
  raise StreamClosed, "Cannot reset stream #{frame.stream_id}"
428
462
  end
@@ -439,8 +473,10 @@ module Protocol
439
473
  rescue ProtocolError => error
440
474
  stream.send_reset_stream(error.code)
441
475
  end
442
- elsif frame.stream_id > @remote_stream_id
443
- # Receiving any frame other than HEADERS or PRIORITY on a stream in this state MUST be treated as a connection error of type PROTOCOL_ERROR.
476
+ elsif closed_stream_id?(frame.stream_id)
477
+ # Ignore.
478
+ else
479
+ # Receiving any frame other than HEADERS or PRIORITY on a stream in this state (idle) MUST be treated as a connection error of type PROTOCOL_ERROR.
444
480
  raise ProtocolError, "Cannot update window of idle stream #{frame.stream_id}"
445
481
  end
446
482
  end
@@ -84,7 +84,7 @@ module Protocol
84
84
  def receive_window_update(frame)
85
85
  amount = frame.unpack
86
86
 
87
- # puts "expanding remote_window=#{@remote_window} by #{amount}"
87
+ # Async.logger.info(self) {"expanding remote_window=#{@remote_window} by #{amount}"}
88
88
 
89
89
  if amount != 0
90
90
  @remote_window.expand(amount)
@@ -103,7 +103,7 @@ module Protocol
103
103
  # Async.logger.debug(self, name: "write") {frame.inspect}
104
104
 
105
105
  frame.write(@stream)
106
-
106
+
107
107
  # Don't call @stream.flush here because it can cause significant contention if there is a semaphore around this method.
108
108
  # @stream.flush
109
109
 
@@ -27,6 +27,14 @@ module Protocol
27
27
  super(framer, 2)
28
28
  end
29
29
 
30
+ def local_stream_id?(id)
31
+ id.even?
32
+ end
33
+
34
+ def remote_stream_id?(id)
35
+ id.odd?
36
+ end
37
+
30
38
  def valid_remote_stream_id?(stream_id)
31
39
  stream_id.odd?
32
40
  end
@@ -130,7 +130,6 @@ module Protocol
130
130
 
131
131
  # The stream is being closed because the connection is being closed.
132
132
  def close(error = nil)
133
- @connection.delete(@id)
134
133
  end
135
134
 
136
135
  def maximum_frame_size
@@ -247,6 +246,7 @@ module Protocol
247
246
  # @param error_code [Integer] the error code if the stream was closed due to a stream reset.
248
247
  def close!(error_code = nil)
249
248
  @state = :closed
249
+ @connection.delete(@id)
250
250
 
251
251
  if error_code
252
252
  error = StreamError.new("Stream closed!", error_code)
@@ -352,16 +352,10 @@ module Protocol
352
352
  end
353
353
  end
354
354
 
355
- def ignore_reset_stream(frame)
356
- # Async.logger.warn(self) {"Received reset stream (#{error_code}) in state: #{@state}!"}
357
- end
358
-
359
355
  def receive_reset_stream(frame)
360
356
  if @state == :idle
361
357
  # If a RST_STREAM frame identifying an idle stream is received, the recipient MUST treat this as a connection error (Section 5.4.1) of type PROTOCOL_ERROR.
362
358
  raise ProtocolError, "Cannot receive reset stream in state: #{@state}!"
363
- elsif self.closed?
364
- ignore_reset_stream(frame)
365
359
  else
366
360
  error_code = frame.unpack
367
361
 
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Protocol
22
22
  module HTTP2
23
- VERSION = "0.11.1"
23
+ VERSION = "0.11.2"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-http2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: 0.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-17 00:00:00.000000000 Z
11
+ date: 2020-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: protocol-hpack
@@ -153,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  - !ruby/object:Gem::Version
154
154
  version: '0'
155
155
  requirements: []
156
- rubygems_version: 3.0.6
156
+ rubygems_version: 3.1.2
157
157
  signing_key:
158
158
  specification_version: 4
159
159
  summary: A low level implementation of the HTTP/2 protocol.