diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-08-04 19:31:03 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-08-07 10:04:51 -0700 |
| commit | 9e5048c3a5be479d9ad72d1d004d385f2fdc8615 (patch) | |
| tree | 6e91dcaa9d2379e7282257fde261942948e1f68f /lib/std/http | |
| parent | fef41c66dbe9e6ce3e9567b7d6d06ebf4d0cba06 (diff) | |
| download | zig-9e5048c3a5be479d9ad72d1d004d385f2fdc8615.tar.gz zig-9e5048c3a5be479d9ad72d1d004d385f2fdc8615.zip | |
fetch: update for new http API
it's not quite finished because I need to make it not copy the Resource
Diffstat (limited to 'lib/std/http')
| -rw-r--r-- | lib/std/http/Client.zig | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/std/http/Client.zig b/lib/std/http/Client.zig index 6660761930..5b817af467 100644 --- a/lib/std/http/Client.zig +++ b/lib/std/http/Client.zig @@ -682,7 +682,7 @@ pub const Response = struct { /// /// See also: /// * `readerDecompressing` - pub fn reader(response: *Response, buffer: []u8) *Reader { + pub fn reader(response: *const Response, buffer: []u8) *Reader { const req = response.request; if (!req.method.responseHasBody()) return .ending; const head = &response.head; @@ -805,6 +805,11 @@ pub const Request = struct { unhandled = std.math.maxInt(u16), _, + pub fn init(n: u16) RedirectBehavior { + assert(n != std.math.maxInt(u16)); + return @enumFromInt(n); + } + pub fn subtractOne(rb: *RedirectBehavior) void { switch (rb.*) { .not_allowed => unreachable, @@ -855,6 +860,14 @@ pub const Request = struct { return result; } + /// Transfers the HTTP head and body over the connection and flushes. + pub fn sendBodyComplete(r: *Request, body: []u8) Writer.Error!void { + r.transfer_encoding = .{ .content_length = body.len }; + var bw = try sendBodyUnflushed(r, body); + bw.writer.end = body.len; + try bw.end(); + } + /// Transfers the HTTP head over the connection, which is not flushed until /// `BodyWriter.flush` or `BodyWriter.end` is called. /// @@ -1296,7 +1309,7 @@ pub const basic_authorization = struct { pub fn value(uri: Uri, out: []u8) []u8 { var bw: Writer = .fixed(out); write(uri, &bw) catch unreachable; - return bw.getWritten(); + return bw.buffered(); } pub fn write(uri: Uri, out: *Writer) Writer.Error!void { |
