Skip to content

Commit 11fab9c

Browse files
committed
Tests.
1 parent 524721f commit 11fab9c

File tree

5 files changed

+75
-1
lines changed

5 files changed

+75
-1
lines changed

fixtures/protocol/http2/a_frame.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Released under the MIT License.
44
# Copyright, 2019-2024, by Samuel Williams.
55

6+
require "socket"
67
require "protocol/http2/framer"
78

89
module Protocol

lib/protocol/http2/connection.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
require_relative "flow_controlled"
99

1010
require "protocol/hpack"
11+
require "protocol/http/header/priority"
1112

1213
module Protocol
1314
module HTTP2
@@ -407,6 +408,7 @@ def receive_priority_update(frame)
407408

408409
stream_id, value = frame.unpack
409410

411+
# Apparently you can set the priority of idle streams, but I'm not sure why that makes sense, so for now let's ignore it.
410412
if stream = @streams[stream_id]
411413
stream.priority = Protocol::HTTP::Header::Priority.new(value)
412414
end

lib/protocol/http2/framer.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ module HTTP2
3030
GoawayFrame,
3131
WindowUpdateFrame,
3232
ContinuationFrame,
33+
nil,
34+
nil,
35+
nil,
36+
nil,
37+
nil,
38+
nil,
3339
PriorityUpdateFrame,
3440
].freeze
3541

lib/protocol/http2/priority_update_frame.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class PriorityUpdateFrame < Frame
2424
def unpack
2525
data = super
2626

27-
prioritized_stream_id = data.unpack(FORMAT)
27+
prioritized_stream_id = data.unpack1(FORMAT)
2828

2929
return prioritized_stream_id, data.byteslice(4, data.bytesize - 4)
3030
end
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# frozen_string_literal: true
2+
# Released under the MIT License.
3+
# Copyright, 2019-2024, by Samuel Williams.
4+
5+
require "protocol/http2/priority_update_frame"
6+
7+
require "protocol/http2/a_frame"
8+
require "protocol/http2/connection_context"
9+
10+
describe Protocol::HTTP2::PriorityUpdateFrame do
11+
let(:frame) {subject.new}
12+
13+
it_behaves_like Protocol::HTTP2::AFrame do
14+
before do
15+
frame.pack 1, "u=1, i"
16+
end
17+
18+
it "applies to the connection" do
19+
expect(frame).to be(:connection?)
20+
end
21+
end
22+
23+
with "client/server connection" do
24+
include_context Protocol::HTTP2::ConnectionContext
25+
26+
def before
27+
client.open!
28+
server.open!
29+
30+
super
31+
end
32+
33+
it "fails with protocol error if stream id is not zero" do
34+
# This isn't a valid for the frame stream_id:
35+
frame.stream_id = 1
36+
37+
# This is a valid stream payload:
38+
frame.pack stream.id, "u=1, i"
39+
40+
expect do
41+
frame.apply(server)
42+
end.to raise_exception(Protocol::HTTP2::ProtocolError)
43+
end
44+
45+
let(:stream) {client.create_stream}
46+
47+
it "updates the priority of a stream" do
48+
stream.send_headers [["content-type", "text/plain"]]
49+
server.read_frame
50+
51+
expect(server).to receive(:receive_priority_update)
52+
expect(stream.priority).to be_nil
53+
54+
frame.pack stream.id, "u=1, i"
55+
client.write_frame(frame)
56+
57+
inform server.read_frame
58+
59+
server_stream = server.streams[stream.id]
60+
expect(server_stream).not.to be_nil
61+
62+
expect(server_stream.priority).to be == ["u=1", "i"]
63+
end
64+
end
65+
end

0 commit comments

Comments
 (0)