Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Nov 28, 2024
1 parent 4b680eb commit 524721f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/protocol/http2/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,18 @@ def receive_push_promise(frame)
raise ProtocolError, "Unable to receive push promise!"
end

def receive_priority_update(frame)
if frame.stream_id != 0
raise ProtocolError, "Invalid stream id: #{frame.stream_id}"
end

stream_id, value = frame.unpack

if stream = @streams[stream_id]
stream.priority = Protocol::HTTP::Header::Priority.new(value)
end
end

def client_stream_id?(id)
id.odd?
end
Expand Down
2 changes: 2 additions & 0 deletions lib/protocol/http2/framer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require_relative "goaway_frame"
require_relative "window_update_frame"
require_relative "continuation_frame"
require_relative "priority_update_frame"

module Protocol
module HTTP2
Expand All @@ -29,6 +30,7 @@ module HTTP2
GoawayFrame,
WindowUpdateFrame,
ContinuationFrame,
PriorityUpdateFrame,
].freeze

# Default connection "fast-fail" preamble string as defined by the spec.
Expand Down
41 changes: 41 additions & 0 deletions lib/protocol/http2/priority_update_frame.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2019-2024, by Samuel Williams.

require_relative "frame"
require_relative "padded"
require_relative "continuation_frame"

module Protocol
module HTTP2
# The PRIORITY_UPDATE frame is used by clients to signal the initial priority of a response, or to reprioritize a response or push stream. It carries the stream ID of the response and the priority in ASCII text, using the same representation as the Priority header field value.
#
# +-+-------------+-----------------------------------------------+
# |R| Prioritized Stream ID (31) |
# +-+-----------------------------+-------------------------------+
# | Priority Field Value (*) ...
# +---------------------------------------------------------------+
#
class PriorityUpdateFrame < Frame
TYPE = 0x10
FORMAT = "N".freeze

def unpack
data = super

prioritized_stream_id = data.unpack(FORMAT)

return prioritized_stream_id, data.byteslice(4, data.bytesize - 4)
end

def pack(prioritized_stream_id, data, **options)
super([prioritized_stream_id].pack(FORMAT) + data, **options)
end

def apply(connection)
connection.receive_priority_update(self)
end
end
end
end
4 changes: 4 additions & 0 deletions lib/protocol/http2/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def initialize(connection, id, state = :idle)

@local_window = Window.new(@connection.local_settings.initial_window_size)
@remote_window = Window.new(@connection.remote_settings.initial_window_size)

@priority = nil
end

# The connection this stream belongs to.
Expand All @@ -90,6 +92,8 @@ def initialize(connection, id, state = :idle)
attr :local_window
attr :remote_window

attr_accessor :priority

def maximum_frame_size
@connection.available_frame_size
end
Expand Down

0 comments on commit 524721f

Please sign in to comment.