Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions http/h2_stream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,15 @@ frame_handlers[0x1] = function(stream, flags, payload)
pos = pos + 5

local new_parent = stream.connection.streams[stream_dep]
if new_parent == nil then
error("parent doesn't exist " .. stream_dep) -- FIXME

-- 5.3.1. Stream Dependencies
-- A dependency on a stream that is not currently in the tree
-- results in that stream being given a default priority
if new_parent then
local ok, err = new_parent:reprioritise(stream, exclusive)
if not ok then return nil, err end
stream.weight = weight
end
local ok, err = new_parent:reprioritise(stream, exclusive)
if not ok then return nil, err end
stream.weight = weight
end

if #payload - pos + 1 > MAX_HEADER_BUFFER_SIZE then
Expand Down
31 changes: 31 additions & 0 deletions spec/h2_connection_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,37 @@ describe("http2 connection", function()
assert.truthy(cq:empty())
end)
end)
describe("priority on missing stream", function()
it("sets default priority for streams with missing parent", function()
local cq = cqueues.new()
local c, s = cs.pair()
cq:wrap(function()
c = h2_connection.new(c, "client")
local client_stream = c:new_stream()
local req_headers = new_headers()
req_headers:append(":method", "GET")
req_headers:append(":scheme", "http")
req_headers:append(":path", "/")
-- Encode HEADER payload and send with dependency on missing stream
c.encoding_context:encode_headers(req_headers)
local payload = c.encoding_context:render_data()
c.encoding_context:clear_data()
assert(client_stream:write_headers_frame(payload, true, true, nil, nil, 99, 99))
client_stream:shutdown()
assert(c:close())
end)
cq:wrap(function()
s = h2_connection.new(s, "server")
local stream = assert(s:get_next_incoming_stream())
-- Check if set to default priority instead of missing parent
assert.is_not.same(stream.weight, 99)
stream:shutdown()
assert(s:close())
end)
assert_loop(cq, TEST_TIMEOUT)
assert.truthy(cq:empty())
end)
end)
describe("settings", function()
it("correctly handles odd frame sizes", function()
local c = cs.pair()
Expand Down