commit 0488c3cb52a75ffa4fa73b385d3d6e79cc6da774 (tree)
parent 1acb3162b7e24e6badad4aff37dbeac09f47f165
Author: Ryan Liptak <squeek502@hotmail.com>
Date: Sat, 22 Apr 2023 16:34:33 -0700
std.http: Always initialize `response.headers` in Client.request
Before this change, if a request errored before getting its `response.headers` initialized, then it would attempt to `deinit` `response.headers` which would still be `undefined`. Since all locations that set `response.headers` use the same code, it can just be done upfront in `request` instead.
Closes #15380
Diffstat:
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/lib/std/http/Client.zig b/lib/std/http/Client.zig
@@ -645,7 +645,6 @@ pub const Request = struct {
if (req.response.parser.state.isContent()) break;
}
- req.response.headers = http.Headers{ .allocator = req.client.allocator, .owned = false };
try req.response.parse(req.response.parser.header_bytes.items);
if (req.response.status == .switching_protocols) {
@@ -765,7 +764,7 @@ pub const Request = struct {
}
if (has_trail) {
- req.response.headers = http.Headers{ .allocator = req.client.allocator, .owned = false };
+ req.response.headers.clearRetainingCapacity();
// The response headers before the trailers are already guaranteed to be valid, so they will always be parsed again and cannot return an error.
// This will *only* fail for a malformed trailer.
@@ -1019,7 +1018,7 @@ pub fn request(client: *Client, method: http.Method, uri: Uri, headers: http.Hea
.status = undefined,
.reason = undefined,
.version = undefined,
- .headers = undefined,
+ .headers = http.Headers{ .allocator = client.allocator, .owned = false },
.parser = switch (options.header_strategy) {
.dynamic => |max| proto.HeadersParser.initDynamic(max),
.static => |buf| proto.HeadersParser.initStatic(buf),