Skip to content

Commit

Permalink
Remove suport for priority frame and stream dependencies. (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix authored Nov 28, 2024
1 parent 76a6cda commit 23ea145
Show file tree
Hide file tree
Showing 23 changed files with 87 additions and 898 deletions.
2 changes: 1 addition & 1 deletion examples/http2/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
]

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

puts "Waiting for response..."
$count = 0
Expand Down
2 changes: 1 addition & 1 deletion examples/http2/requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
]

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

def stream.process_headers(frame)
headers = super
Expand Down
4 changes: 4 additions & 0 deletions lib/protocol/http2/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def send_connection_preface(settings = [])
if @state == :new
@framer.write_connection_preface

# We don't support RFC7540 priorities:
settings = settings.to_a
settings << [Settings::NO_RFC7540_PRIORITIES, 1]

send_settings(settings)

yield if block_given?
Expand Down
42 changes: 7 additions & 35 deletions lib/protocol/http2/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# Copyright, 2023, by Marco Concetto Rudilosso.

require_relative "framer"
require_relative "dependency"
require_relative "flow_controlled"

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

# Hash(Integer, Dependency)
@dependency = Dependency.new(self, 0)
@dependencies = {0 => @dependency}

@framer = framer

# The next stream id to use:
Expand Down Expand Up @@ -95,7 +90,6 @@ def closed?

def delete(id)
@streams.delete(id)
@dependencies[id]&.delete!
end

# Close the underlying framer and all streams.
Expand Down Expand Up @@ -402,22 +396,6 @@ def receive_headers(frame)
end
end

def send_priority(stream_id, priority)
frame = PriorityFrame.new(stream_id)
frame.pack(priority)

write_frame(frame)
end

# Sets the priority for an incoming stream.
def receive_priority(frame)
if dependency = @dependencies[frame.stream_id]
dependency.receive_priority(frame)
elsif idle_stream_id?(frame.stream_id)
Dependency.create(self, frame.stream_id, frame.unpack)
end
end

def receive_push_promise(frame)
raise ProtocolError, "Unable to receive push promise!"
end
Expand Down Expand Up @@ -470,23 +448,17 @@ def receive_reset_stream(frame)
end
end

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

# Console.info(self) do |buffer|
# @dependencies.each do |id, dependency|
# buffer.puts "- #{dependency}"
# end
#
# buffer.puts
#
# @dependency.print_hierarchy(buffer)
# end

@dependency.consume_window(size)
@streams.each_value do |stream|
if stream.active?
stream.window_updated(size)
end
end
end

def receive_window_update(frame)
Expand Down
245 changes: 0 additions & 245 deletions lib/protocol/http2/dependency.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/protocol/http2/flow_controlled.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def receive_window_update(frame)
end

# The window has been expanded by the given amount.
# @param size [Integer] the maximum amount of data to send.
# @parameter size [Integer] the maximum amount of data to send.
# @return [Boolean] whether the window update was used or not.
def window_updated(size)
return false
Expand Down
4 changes: 2 additions & 2 deletions lib/protocol/http2/frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Frame
# The base class does not have any specific type index:
TYPE = nil

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

# Decodes common 9-byte header.
#
# @param buffer [String]
# @parameter buffer [String]
def self.parse_header(buffer)
length_hi, length_lo, type, flags, stream_id = buffer.unpack(HEADER_FORMAT)
length = (length_hi << LENGTH_HISHIFT) | length_lo
Expand Down
3 changes: 1 addition & 2 deletions lib/protocol/http2/framer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

require_relative "data_frame"
require_relative "headers_frame"
require_relative "priority_frame"
require_relative "reset_stream_frame"
require_relative "settings_frame"
require_relative "push_promise_frame"
Expand All @@ -22,7 +21,7 @@ module HTTP2
FRAMES = [
DataFrame,
HeadersFrame,
PriorityFrame,
nil, # PriorityFrame is deprecated / removed.
ResetStreamFrame,
SettingsFrame,
PushPromiseFrame,
Expand Down
Loading

0 comments on commit 23ea145

Please sign in to comment.