1
Fork 0

Merge _set_content_length into new_request_body

This commit is contained in:
Drew DeVault 2023-02-12 13:14:19 +01:00
parent 5038e0031a
commit 337d063f15

View file

@ -91,21 +91,18 @@ fn new_request_body(
) request = {
let req = new_request(client, method, target);
req.body = body;
request_set_content_length(&req, body);
return req;
};
fn request_set_content_length(req: *request, body: io::handle) void = {
const prev = match (io::seek(body, 0, io::whence::CUR)) {
const offs = match (io::seek(body, 0, io::whence::CUR)) {
case let off: io::off =>
yield off;
case io::error =>
header_add(&req.header, "Transfer-Encoding", "chunked");
return;
return req;
};
const ln = io::seek(body, 0, io::whence::END)!;
io::seek(body, prev, io::whence::SET)!;
io::seek(body, offs, io::whence::SET)!;
header_add(&req.header, "Content-Length", strconv::ztos(ln: size));
return req;
};
fn uri_origin_form(target: *uri::uri) uri::uri = {