Skip to content

Commit 02b173f

Browse files
committed
fix: set headers_in_progress earlier
This change avoids calling `new_headers` more than once. Previously, the headers instance would be created before a potential recursive call.
1 parent 3af5055 commit 02b173f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

http/h1_stream.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ function stream_methods:read_headers(timeout)
261261
local is_trailers = self.body_read_type == "chunked"
262262
local headers = self.headers_in_progress
263263
if not headers then
264-
headers = new_headers()
265-
if is_trailers then -- luacheck: ignore 542
264+
if is_trailers then
265+
headers = new_headers()
266266
elseif self.type == "server" then
267267
if self.state == "half closed (local)" then
268268
return nil
@@ -279,6 +279,7 @@ function stream_methods:read_headers(timeout)
279279
end
280280
self.req_method = method
281281
self.peer_version = httpversion
282+
headers = new_headers()
282283
headers:append(":method", method)
283284
if method == "CONNECT" then
284285
headers:append(":authority", path)
@@ -310,6 +311,7 @@ function stream_methods:read_headers(timeout)
310311
return nil, status_code, reason_phrase
311312
end
312313
self.peer_version = httpversion
314+
headers = new_headers()
313315
headers:append(":status", status_code)
314316
-- reason phase intentionally does not exist in HTTP2; discard for consistency
315317
end

0 commit comments

Comments
 (0)