protocol-http2 0.7.2 → 0.7.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6122b81524b5ecd390cf46cb06d3dbbc8299651e3b83170477b0bfd710352cf
4
- data.tar.gz: 73756e9adea21ed0bddd7d3c8b49032e8e0c0014d3905c093663c9d2b2474601
3
+ metadata.gz: 3b97c3d3611a531fe2facdfe1d21540e45c9857cb83d1d4f5eca735c12efbabe
4
+ data.tar.gz: 07bfed2bc270bea6fcc2e62caf5cf46cb2e511acbcb563603651223de3d41869
5
5
  SHA512:
6
- metadata.gz: c12e3e9a9ef1d1461a3c08d6cb1c52c9f38551e7f37da0ef6c70d998c808a6b6bd48138a4509e108279255d5218c6eb72c6524b9e5b48066d9431a6190468a77
7
- data.tar.gz: 9f909f2f0b3fbb3914f22b9c01d8ede5a78bb5734be429d152b0b28574447e5886240170126b83c47426f38f14eea5ffb8c4839e51bb1a553bdf0dcd088bd1b8
6
+ metadata.gz: f9a90343af8732527276180fcb417b1493476bd20459b1c849cba6d9935fae8f8eb07bef20ee9750b3da8f8763586ac719815793c07ad4cc6079f73b0b1b91eb
7
+ data.tar.gz: f5d27cb750a6e14c02fdeede7308bf0ed180c1fe92b2e6cf982525267591b70632123f22459d014f394efc987cef3af0e47be629f4ac3550f1518c377c9f8dbe
@@ -110,9 +110,7 @@ module Protocol
110
110
  end
111
111
 
112
112
  def encode_headers(headers, buffer = String.new.b)
113
- HPACK::Compressor.new(buffer, @encoder).encode(headers)
114
-
115
- return buffer
113
+ HPACK::Compressor.new(buffer, @encoder, table_size_limit: @remote_settings.header_table_size).encode(headers)
116
114
  end
117
115
 
118
116
  def decode_headers(data)
@@ -142,7 +140,7 @@ module Protocol
142
140
  def exclusive_child(stream)
143
141
  stream.children = @children
144
142
 
145
- @children.each do |child|
143
+ @children.each_value do |child|
146
144
  child.dependent_id = stream.id
147
145
  end
148
146
 
@@ -231,25 +229,12 @@ module Protocol
231
229
  @framer.write_frame(frame)
232
230
  end
233
231
 
234
- def send_ping(data)
235
- if @state != :closed
236
- frame = PingFrame.new
237
- frame.pack data
238
-
239
- write_frame(frame)
240
- else
241
- raise ProtocolError, "Cannot send ping in state #{@state}"
242
- end
243
- end
244
-
245
232
  def update_local_settings(changes)
246
233
  capacity = @local_settings.initial_window_size
247
234
 
248
235
  @streams.each_value do |stream|
249
236
  stream.local_window.capacity = capacity
250
237
  end
251
-
252
- @decoder.table_size = @local_settings.header_table_size
253
238
  end
254
239
 
255
240
  def update_remote_settings(changes)
@@ -258,8 +243,6 @@ module Protocol
258
243
  @streams.each_value do |stream|
259
244
  stream.remote_window.capacity = capacity
260
245
  end
261
-
262
- @encoder.table_size = @remote_settings.header_table_size
263
246
  end
264
247
 
265
248
  # In addition to changing the flow-control window for streams that are not yet active, a SETTINGS frame can alter the initial flow-control window size for streams with active flow-control windows (that is, streams in the "open" or "half-closed (remote)" state). When the value of SETTINGS_INITIAL_WINDOW_SIZE changes, a receiver MUST adjust the size of all stream flow-control windows that it maintains by the difference between the new value and the old value.
@@ -305,6 +288,17 @@ module Protocol
305
288
  end
306
289
  end
307
290
 
291
+ def send_ping(data)
292
+ if @state != :closed
293
+ frame = PingFrame.new
294
+ frame.pack data
295
+
296
+ write_frame(frame)
297
+ else
298
+ raise ProtocolError, "Cannot send ping in state #{@state}"
299
+ end
300
+ end
301
+
308
302
  def receive_ping(frame)
309
303
  if @state != :closed
310
304
  if frame.stream_id != 0
@@ -393,7 +387,14 @@ module Protocol
393
387
  end
394
388
  end
395
389
 
396
- # On the client and server side, sets the priority for an incoming stream.
390
+ def send_priority(stream_id, priority)
391
+ frame = PriorityFrame.new(stream_id)
392
+ frame.pack(priority)
393
+
394
+ write_frame(frame)
395
+ end
396
+
397
+ # Sets the priority for an incoming stream.
397
398
  def receive_priority(frame)
398
399
  if stream = @streams[frame.stream_id]
399
400
  stream.receive_priority(frame)
@@ -52,8 +52,6 @@ module Protocol
52
52
  CONNECTION_PREFACE_MAGIC = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n".freeze
53
53
 
54
54
  class Framer
55
- # DEBUG = !!ENV['FRAMER_DEBUG']
56
-
57
55
  def initialize(stream, frames = FRAMES)
58
56
  @stream = stream
59
57
  @frames = frames
@@ -86,7 +84,8 @@ module Protocol
86
84
  def read_frame(maximum_frame_size = MAXIMUM_ALLOWED_FRAME_SIZE)
87
85
  # Read the header:
88
86
  length, type, flags, stream_id = read_header
89
- # puts "read_frame: length=#{length} type=#{type} flags=#{flags} stream_id=#{stream_id} -> klass=#{@frames[type].inspect}"
87
+
88
+ # Async.logger.debug(self) {"read_frame: length=#{length} type=#{type} flags=#{flags} stream_id=#{stream_id} -> klass=#{@frames[type].inspect}"}
90
89
 
91
90
  # Allocate the frame:
92
91
  klass = @frames[type] || Frame
@@ -95,13 +94,14 @@ module Protocol
95
94
  # Read the payload:
96
95
  frame.read(@stream, maximum_frame_size)
97
96
 
98
- # DEBUG and puts "read_frame: #{frame.inspect}"
97
+ # Async.logger.debug(self, name: "read") {frame.inspect}
99
98
 
100
99
  return frame
101
100
  end
102
101
 
103
102
  def write_frame(frame)
104
- # DEBUG and puts "write_frame: #{frame.inspect}"
103
+ # Async.logger.debug(self, name: "write") {frame.inspect}
104
+
105
105
  frame.write(@stream)
106
106
 
107
107
  @stream.flush
@@ -27,7 +27,7 @@ module Protocol
27
27
  # Stream Dependency: A 31-bit stream identifier for the stream that
28
28
  # this stream depends on (see Section 5.3). This field is only
29
29
  # present if the PRIORITY flag is set.
30
- Priority = Struct.new(:exclusive, :stream_dependency, :weight) do
30
+ class Priority < Struct.new(:exclusive, :stream_dependency, :weight)
31
31
  FORMAT = "NC".freeze
32
32
  EXCLUSIVE = 1 << 31
33
33
 
@@ -46,6 +46,8 @@ module Protocol
46
46
  def pack
47
47
  if exclusive
48
48
  stream_dependency = self.stream_dependency | EXCLUSIVE
49
+ else
50
+ stream_dependency = self.stream_dependency
49
51
  end
50
52
 
51
53
  return [stream_dependency, self.weight - 1].pack(FORMAT)
@@ -161,7 +161,7 @@ module Protocol
161
161
  def exclusive_child(stream)
162
162
  stream.children = @children
163
163
 
164
- @children.each do |child|
164
+ @children.each_value do |child|
165
165
  child.dependent_id = stream.id
166
166
  end
167
167
 
@@ -182,13 +182,15 @@ module Protocol
182
182
  stream.add_child(self)
183
183
  end
184
184
 
185
- def priority= priority
185
+ def update_priority priority
186
186
  dependent_id = priority.stream_dependency
187
187
 
188
188
  if dependent_id == @id
189
189
  raise ProtocolError, "Stream priority for stream id #{@id} cannot depend on itself!"
190
190
  end
191
191
 
192
+ @weight = priority.weight
193
+
192
194
  if priority.exclusive
193
195
  self.parent&.remove_child(self)
194
196
 
@@ -333,7 +335,7 @@ module Protocol
333
335
  priority, data = frame.unpack
334
336
 
335
337
  if priority
336
- self.priority = priority
338
+ self.update_priority(priority)
337
339
  end
338
340
 
339
341
  @connection.decode_headers(data)
@@ -397,8 +399,23 @@ module Protocol
397
399
  end
398
400
  end
399
401
 
402
+ # Change the priority of the stream both locally and remotely.
403
+ def priority= priority
404
+ send_priority(priority)
405
+ update_priority(priority)
406
+ end
407
+
408
+ # The current local priority of the stream.
409
+ def priority(exclusive = false)
410
+ Priority.new(exclusive, @dependent_id, @weight)
411
+ end
412
+
413
+ def send_priority(priority)
414
+ @connection.send_priority(@id, priority)
415
+ end
416
+
400
417
  def receive_priority(frame)
401
- self.priority = frame.unpack
418
+ self.update_priority(frame.unpack)
402
419
  end
403
420
 
404
421
  def receive_reset_stream(frame)
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Protocol
22
22
  module HTTP2
23
- VERSION = "0.7.2"
23
+ VERSION = "0.7.4"
24
24
  end
25
25
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "protocol-hpack", "~> 1.3"
21
+ spec.add_dependency "protocol-hpack", "~> 1.4"
22
22
  spec.add_dependency "protocol-http", "~> 0.2"
23
23
 
24
24
  spec.add_development_dependency "covered"
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.7.2
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-17 00:00:00.000000000 Z
11
+ date: 2019-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: protocol-hpack
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '1.4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '1.4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: protocol-http
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  - !ruby/object:Gem::Version
151
151
  version: '0'
152
152
  requirements: []
153
- rubygems_version: 3.0.2
153
+ rubygems_version: 3.0.3
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: A low level implementation of the HTTP/2 protocol.