diff --git a/net/http/do.ha b/net/http/do.ha index 535deb0..851da13 100644 --- a/net/http/do.ha +++ b/net/http/do.ha @@ -6,36 +6,30 @@ use net::uri; use net; use os; -type context = struct { - conn: io::handle, - file: bufio::bufstream, - buf: [os::BUFSIZ]u8, -}; - // Performs an HTTP [[request]] with the given [[client]]. The request is // performed synchronously; this function blocks until the server has returned // the response status and all HTTP headers associated with the response. export fn do(client: *client, req: *request) (response | error) = { - let ctx = context { ... }; - assert(req.target.scheme == "http"); // TODO: https const conn = dial::dial_uri("tcp", req.target)?; - ctx.file = bufio::buffered(conn, [], ctx.buf); - bufio::setflush(&ctx.file, []); - fmt::fprintf(&ctx.file, "{} ", req.method)?; + let buf: [os::BUFSIZ]u8 = [0...]; + let file = bufio::buffered(conn, [], buf); + bufio::setflush(&file, []); + + fmt::fprintf(&file, "{} ", req.method)?; // TODO: Support other request-targets than origin-form let target = uri_origin_form(req.target); - uri::fmt(&ctx.file, &target)?; - fmt::fprintf(&ctx.file, " HTTP/1.1\r\n")?; + uri::fmt(&file, &target)?; + fmt::fprintf(&file, " HTTP/1.1\r\n")?; // TODO: Handle Content-Length and Transfer-Encoding chunked/gzip // properly - write_header(&ctx.file, &req.header)?; - fmt::fprintf(&ctx.file, "\r\n")?; - bufio::flush(&ctx.file)?; + write_header(&file, &req.header)?; + fmt::fprintf(&file, "\r\n")?; + bufio::flush(&file)?; match (req.body) { case void =>