Skip to content

Commit d9a367d

Browse files
committed
Fix flag handling when sending headers with priority.
1 parent 5727437 commit d9a367d

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

lib/protocol/http2/headers_frame.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ def pack(priority, data, *arguments, **options)
6868

6969
if priority
7070
buffer << priority.pack
71+
set_flags(PRIORITY)
72+
else
73+
clear_flags(PRIORITY)
7174
end
7275

7376
buffer << data

lib/protocol/http2/stream.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,27 +163,27 @@ def send_headers?
163163
end
164164

165165
# The HEADERS frame is used to open a stream, and additionally carries a header block fragment. HEADERS frames can be sent on a stream in the "idle", "reserved (local)", "open", or "half-closed (remote)" state.
166-
def send_headers(*args)
166+
def send_headers(*arguments)
167167
if @state == :idle
168-
frame = write_headers(*args)
168+
frame = write_headers(*arguments)
169169

170170
if frame.end_stream?
171171
@state = :half_closed_local
172172
else
173173
open!
174174
end
175175
elsif @state == :reserved_local
176-
frame = write_headers(*args)
176+
frame = write_headers(*arguments)
177177

178178
@state = :half_closed_remote
179179
elsif @state == :open
180-
frame = write_headers(*args)
180+
frame = write_headers(*arguments)
181181

182182
if frame.end_stream?
183183
@state = :half_closed_local
184184
end
185185
elsif @state == :half_closed_remote
186-
frame = write_headers(*args)
186+
frame = write_headers(*arguments)
187187

188188
if frame.end_stream?
189189
close!

spec/protocol/http2/dependency_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,32 @@
121121

122122
server.consume_window
123123
end
124+
125+
it "correctly allocates window" do
126+
streams = 4.times.collect{client.create_stream}
127+
128+
top = streams.first
129+
130+
top.send_headers(nil, [])
131+
top.send_reset_stream
132+
133+
2.times {server.read_frame}
134+
135+
# The dependency has been recycled:
136+
expect(server.dependencies).to_not include(top.id)
137+
138+
bottom = streams.last
139+
140+
priority = bottom.priority
141+
priority.stream_dependency = top.id
142+
143+
bottom.send_headers(priority, [])
144+
145+
1.times {server.read_frame}
146+
147+
expect(server.dependencies).to include(bottom.id)
148+
149+
dependency = server.dependencies[bottom.id]
150+
expect(dependency.parent).to be == server.dependency
151+
end
124152
end

0 commit comments

Comments
 (0)