mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 22:35:24 +00:00
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
This commit is contained in:
parent
1acb3162b7
commit
0488c3cb52
@ -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),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user