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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user