12 Commits

Author SHA1 Message Date
Andrew Kelley
125221cce9 std: update to use @memcpy directly 2023-04-28 13:24:43 -07:00
Ryo Ota
bba90b8863 fix HTTP server to handle a chunked transfer coding request 2023-04-24 15:36:35 -07:00
Ryo Ota
afebef2465 create std.http.Server.Response.deinit to handle keepalive connections 2023-04-21 10:17:16 +09:00
Ryo Ota
39c0c24b56 fix memory leaks and add an HTTP test 2023-04-21 02:35:38 +09:00
Ryo Ota
d80e6ca5a6 std.http: add missing InvalidTrailers to ReadError 2023-04-20 12:35:26 +03:00
Nameless
a23c8662b4
std.http: pass Method to request directly, parse trailing headers 2023-04-18 10:28:53 -05:00
Nameless
85221b4e97
std.http: curate some Server errors, fix reading chunked bodies 2023-04-17 19:16:01 -05:00
Nameless
134294230a
std.http: add Headers 2023-04-17 19:15:55 -05:00
Ryo Ota
17af53554e
HTTP client and server send "0\r\n\r\n" when chunked encoding 2023-04-17 13:33:25 +03:00
Nameless
ef6d58ed3b
std.http: add documentation 2023-04-08 09:59:36 -05:00
Nameless
aecbfa3a1e
add buffering to connection instead of the http protocol, to allow passing through upgrades 2023-04-08 09:59:36 -05:00
Nameless
08bdaf3bd6
std.http: add http server
* extract http protocol into protocol.zig, as it is shared between client and server
* coalesce Request and Response back into Client.zig, they don't contain
  any large chunks of code anymore
* http.Server is implemented as basic as possible, a simple example below:

```zig
fn handler(res: *Server.Response) !void {
    while (true) {
        defer res.reset();

        try res.waitForCompleteHead();
        res.headers.transfer_encoding = .{ .content_length = 14 };
        res.headers.connection = res.request.headers.connection;
        try res.sendResponseHead();
        _ = try res.write("Hello, World!\n");

        if (res.connection.closing) break;
    }
}

pub fn main() !void {
    var server = Server.init(std.heap.page_allocator, .{ .reuse_address = true });
    defer server.deinit();

    try server.listen(try net.Address.parseIp("127.0.0.1", 8080));

    while (true) {
        const res = try server.accept(.{ .dynamic = 8192 });

        const thread = try std.Thread.spawn(.{}, handler, .{res});
        thread.detach();
    }
}
```
2023-04-08 09:59:35 -05:00