fetch: update for new http API

it's not quite finished because I need to make it not copy the Resource
This commit is contained in:
Andrew Kelley
2025-08-04 19:31:03 -07:00
parent fef41c66db
commit 9e5048c3a5
3 changed files with 309 additions and 314 deletions

View File

@@ -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 {