Skip to content

Commit 23ea145

Browse files
authored
Remove suport for priority frame and stream dependencies. (#23)
1 parent 76a6cda commit 23ea145

23 files changed

+87
-898
lines changed

examples/http2/request.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
]
3939

4040
puts "Sending request on stream id=#{stream.id} state=#{stream.state}..."
41-
stream.send_headers(nil, headers, Protocol::HTTP2::END_STREAM)
41+
stream.send_headers(headers, Protocol::HTTP2::END_STREAM)
4242

4343
puts "Waiting for response..."
4444
$count = 0

examples/http2/requests.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
]
3636

3737
puts "Sending request on stream id=#{stream.id} state=#{stream.state}..."
38-
stream.send_headers(nil, headers, Protocol::HTTP2::END_STREAM)
38+
stream.send_headers(headers, Protocol::HTTP2::END_STREAM)
3939

4040
def stream.process_headers(frame)
4141
headers = super

lib/protocol/http2/client.rb

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def send_connection_preface(settings = [])
2828
if @state == :new
2929
@framer.write_connection_preface
3030

31+
# We don't support RFC7540 priorities:
32+
settings = settings.to_a
33+
settings << [Settings::NO_RFC7540_PRIORITIES, 1]
34+
3135
send_settings(settings)
3236

3337
yield if block_given?

lib/protocol/http2/connection.rb

+7-35
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# Copyright, 2023, by Marco Concetto Rudilosso.
66

77
require_relative "framer"
8-
require_relative "dependency"
98
require_relative "flow_controlled"
109

1110
require "protocol/hpack"
@@ -23,10 +22,6 @@ def initialize(framer, local_stream_id)
2322
# Hash(Integer, Stream)
2423
@streams = {}
2524

26-
# Hash(Integer, Dependency)
27-
@dependency = Dependency.new(self, 0)
28-
@dependencies = {0 => @dependency}
29-
3025
@framer = framer
3126

3227
# The next stream id to use:
@@ -95,7 +90,6 @@ def closed?
9590

9691
def delete(id)
9792
@streams.delete(id)
98-
@dependencies[id]&.delete!
9993
end
10094

10195
# Close the underlying framer and all streams.
@@ -402,22 +396,6 @@ def receive_headers(frame)
402396
end
403397
end
404398

405-
def send_priority(stream_id, priority)
406-
frame = PriorityFrame.new(stream_id)
407-
frame.pack(priority)
408-
409-
write_frame(frame)
410-
end
411-
412-
# Sets the priority for an incoming stream.
413-
def receive_priority(frame)
414-
if dependency = @dependencies[frame.stream_id]
415-
dependency.receive_priority(frame)
416-
elsif idle_stream_id?(frame.stream_id)
417-
Dependency.create(self, frame.stream_id, frame.unpack)
418-
end
419-
end
420-
421399
def receive_push_promise(frame)
422400
raise ProtocolError, "Unable to receive push promise!"
423401
end
@@ -470,23 +448,17 @@ def receive_reset_stream(frame)
470448
end
471449
end
472450

473-
# Traverse active streams in order of priority and allow them to consume the available flow-control window.
474-
# @param amount [Integer] the amount of data to write. Defaults to the current window capacity.
451+
# Traverse active streams and allow them to consume the available flow-control window.
452+
# @parameter amount [Integer] the amount of data to write. Defaults to the current window capacity.
475453
def consume_window(size = self.available_size)
476454
# Return if there is no window to consume:
477455
return unless size > 0
478456

479-
# Console.info(self) do |buffer|
480-
# @dependencies.each do |id, dependency|
481-
# buffer.puts "- #{dependency}"
482-
# end
483-
#
484-
# buffer.puts
485-
#
486-
# @dependency.print_hierarchy(buffer)
487-
# end
488-
489-
@dependency.consume_window(size)
457+
@streams.each_value do |stream|
458+
if stream.active?
459+
stream.window_updated(size)
460+
end
461+
end
490462
end
491463

492464
def receive_window_update(frame)

lib/protocol/http2/dependency.rb

-245
This file was deleted.

lib/protocol/http2/flow_controlled.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def receive_window_update(frame)
7878
end
7979

8080
# The window has been expanded by the given amount.
81-
# @param size [Integer] the maximum amount of data to send.
81+
# @parameter size [Integer] the maximum amount of data to send.
8282
# @return [Boolean] whether the window update was used or not.
8383
def window_updated(size)
8484
return false

lib/protocol/http2/frame.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Frame
3434
# The base class does not have any specific type index:
3535
TYPE = nil
3636

37-
# @param length [Integer] the length of the payload, or nil if the header has not been read yet.
37+
# @parameter length [Integer] the length of the payload, or nil if the header has not been read yet.
3838
def initialize(stream_id = 0, flags = 0, type = self.class::TYPE, length = nil, payload = nil)
3939
@stream_id = stream_id
4040
@flags = flags
@@ -134,7 +134,7 @@ def header
134134

135135
# Decodes common 9-byte header.
136136
#
137-
# @param buffer [String]
137+
# @parameter buffer [String]
138138
def self.parse_header(buffer)
139139
length_hi, length_lo, type, flags, stream_id = buffer.unpack(HEADER_FORMAT)
140140
length = (length_hi << LENGTH_HISHIFT) | length_lo

lib/protocol/http2/framer.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
require_relative "data_frame"
99
require_relative "headers_frame"
10-
require_relative "priority_frame"
1110
require_relative "reset_stream_frame"
1211
require_relative "settings_frame"
1312
require_relative "push_promise_frame"
@@ -22,7 +21,7 @@ module HTTP2
2221
FRAMES = [
2322
DataFrame,
2423
HeadersFrame,
25-
PriorityFrame,
24+
nil, # PriorityFrame is deprecated / removed.
2625
ResetStreamFrame,
2726
SettingsFrame,
2827
PushPromiseFrame,

0 commit comments

Comments
 (0)