-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce
PRIORITY_UPDATE
frame and priority tracking per stream. (#25
- Loading branch information
Showing
12 changed files
with
225 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.unpack1(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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# frozen_string_literal: true | ||
# Released under the MIT License. | ||
# Copyright, 2019-2024, by Samuel Williams. | ||
|
||
require "protocol/http2/priority_update_frame" | ||
|
||
require "protocol/http2/a_frame" | ||
require "protocol/http2/connection_context" | ||
|
||
describe Protocol::HTTP2::PriorityUpdateFrame do | ||
let(:frame) {subject.new} | ||
|
||
it_behaves_like Protocol::HTTP2::AFrame do | ||
before do | ||
frame.pack 1, "u=1, i" | ||
end | ||
|
||
it "applies to the connection" do | ||
expect(frame).to be(:connection?) | ||
end | ||
end | ||
|
||
with "client/server connection" do | ||
include_context Protocol::HTTP2::ConnectionContext | ||
|
||
def before | ||
client.open! | ||
server.open! | ||
|
||
super | ||
end | ||
|
||
it "fails with protocol error if stream id is not zero" do | ||
# This isn't a valid for the frame stream_id: | ||
frame.stream_id = 1 | ||
|
||
# This is a valid stream payload: | ||
frame.pack stream.id, "u=1, i" | ||
|
||
expect do | ||
frame.apply(server) | ||
end.to raise_exception(Protocol::HTTP2::ProtocolError) | ||
end | ||
|
||
let(:stream) {client.create_stream} | ||
|
||
it "updates the priority of a stream" do | ||
stream.send_headers [["content-type", "text/plain"]] | ||
server.read_frame | ||
|
||
expect(server).to receive(:receive_priority_update) | ||
expect(stream.priority).to be_nil | ||
|
||
frame.pack stream.id, "u=1, i" | ||
client.write_frame(frame) | ||
|
||
inform server.read_frame | ||
|
||
server_stream = server.streams[stream.id] | ||
expect(server_stream).not.to be_nil | ||
|
||
expect(server_stream.priority).to be == ["u=1", "i"] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.