aboutsummaryrefslogtreecommitdiff
path: root/lib/std/http/Client.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2024-02-26 17:04:28 +0100
committerAndrew Kelley <andrew@ziglang.org>2024-02-26 20:11:43 -0800
commit4e2570baafb587c679ee0fc5e113ddeb36522a5d (patch)
treee74f607290693900c9e863d427e9a78ee5f03826 /lib/std/http/Client.zig
parent8775d8bbcef347640c6ae7e73da02ca6eff1d669 (diff)
downloadzig-4e2570baafb587c679ee0fc5e113ddeb36522a5d.tar.gz
zig-4e2570baafb587c679ee0fc5e113ddeb36522a5d.zip
http: fix fetching a github release
* Support different keep alive defaults with different http versions. * Fix incorrect usage of `copyBackwards`, which copies in a backwards direction allowing data to be moved forward in a buffer, not backwards in a buffer.
Diffstat (limited to 'lib/std/http/Client.zig')
-rw-r--r--lib/std/http/Client.zig12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/std/http/Client.zig b/lib/std/http/Client.zig
index 1ffe1e8ea3..49843fb405 100644
--- a/lib/std/http/Client.zig
+++ b/lib/std/http/Client.zig
@@ -430,7 +430,7 @@ pub const Response = struct {
/// Points into the user-provided `server_header_buffer`.
content_disposition: ?[]const u8 = null,
- keep_alive: bool = false,
+ keep_alive: bool,
/// If present, the number of bytes in the response body.
content_length: ?u64 = null,
@@ -477,6 +477,10 @@ pub const Response = struct {
res.version = version;
res.status = status;
res.reason = reason;
+ res.keep_alive = switch (version) {
+ .@"HTTP/1.0" => false,
+ .@"HTTP/1.1" => true,
+ };
while (it.next()) |line| {
if (line.len == 0) return;
@@ -684,9 +688,10 @@ pub const Request = struct {
req.response.parser.reset();
req.response = .{
+ .version = undefined,
.status = undefined,
.reason = undefined,
- .version = undefined,
+ .keep_alive = undefined,
.parser = req.response.parser,
};
}
@@ -1564,9 +1569,10 @@ pub fn open(
.redirect_behavior = options.redirect_behavior,
.handle_continue = options.handle_continue,
.response = .{
+ .version = undefined,
.status = undefined,
.reason = undefined,
- .version = undefined,
+ .keep_alive = undefined,
.parser = proto.HeadersParser.init(options.server_header_buffer),
},
.headers = options.headers,