Skip to content

Commit 6c0f833

Browse files
committed
fetch: update for new http API
it's not quite finished because I need to make it not copy the Resource
1 parent ecf7feb commit 6c0f833

File tree

3 files changed

+311
-316
lines changed

3 files changed

+311
-316
lines changed

lib/std/http/Client.zig

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ pub const Response = struct {
682682
///
683683
/// See also:
684684
/// * `readerDecompressing`
685-
pub fn reader(response: *Response, buffer: []u8) *Reader {
685+
pub fn reader(response: *const Response, buffer: []u8) *Reader {
686686
const req = response.request;
687687
if (!req.method.responseHasBody()) return .ending;
688688
const head = &response.head;
@@ -805,6 +805,11 @@ pub const Request = struct {
805805
unhandled = std.math.maxInt(u16),
806806
_,
807807

808+
pub fn init(n: u16) RedirectBehavior {
809+
assert(n != std.math.maxInt(u16));
810+
return @enumFromInt(n);
811+
}
812+
808813
pub fn subtractOne(rb: *RedirectBehavior) void {
809814
switch (rb.*) {
810815
.not_allowed => unreachable,
@@ -855,6 +860,14 @@ pub const Request = struct {
855860
return result;
856861
}
857862

863+
/// Transfers the HTTP head and body over the connection and flushes.
864+
pub fn sendBodyComplete(r: *Request, body: []u8) Writer.Error!void {
865+
r.transfer_encoding = .{ .content_length = body.len };
866+
var bw = try sendBodyUnflushed(r, body);
867+
bw.writer.end = body.len;
868+
try bw.end();
869+
}
870+
858871
/// Transfers the HTTP head over the connection, which is not flushed until
859872
/// `BodyWriter.flush` or `BodyWriter.end` is called.
860873
///
@@ -1296,7 +1309,7 @@ pub const basic_authorization = struct {
12961309
pub fn value(uri: Uri, out: []u8) []u8 {
12971310
var bw: Writer = .fixed(out);
12981311
write(uri, &bw) catch unreachable;
1299-
return bw.getWritten();
1312+
return bw.buffered();
13001313
}
13011314

13021315
pub fn write(uri: Uri, out: *Writer) Writer.Error!void {

0 commit comments

Comments
 (0)