1
Fork 0

net::http::do: place buffer on stack

We can afford 4K of stack space
This commit is contained in:
Drew DeVault 2023-02-10 10:27:06 +01:00
parent 8ccb846c55
commit 859c8dc06e

View file

@ -9,18 +9,14 @@ use os;
type context = struct { type context = struct {
conn: io::handle, conn: io::handle,
file: bufio::bufstream, file: bufio::bufstream,
buf: []u8, buf: [os::BUFSIZ]u8,
}; };
// Performs an HTTP [[request]] with the given [[client]]. The request is // Performs an HTTP [[request]] with the given [[client]]. The request is
// performed synchronously; this function blocks until the server has returned // performed synchronously; this function blocks until the server has returned
// the response status and all HTTP headers associated with the response. // the response status and all HTTP headers associated with the response.
export fn do(client: *client, req: *request) (response | error) = { export fn do(client: *client, req: *request) (response | error) = {
let ctx = context { let ctx = context { ... };
buf = alloc([0...], os::BUFSIZ),
...
};
defer free(ctx.buf);
assert(req.target.scheme == "http"); // TODO: https assert(req.target.scheme == "http"); // TODO: https
const conn = dial::dial_uri("tcp", req.target)?; const conn = dial::dial_uri("tcp", req.target)?;