Commit graph

172 commits

Author SHA1 Message Date
Nameless
3817c7382b
std.http: connectUnix return Unsupported on targets without unix sockets 2023-08-29 21:42:53 -05:00
Nameless
aa090a49d9
std.http: handle expect:100-continue and continue responses 2023-08-29 21:42:53 -05:00
Nameless
5d40338f21
std.http: add Client.fetch and improve redirect logic 2023-08-29 21:42:53 -05:00
Jay Petacat
ff61c42879 std: Rename TailQueue to DoublyLinkedList
`TailQueue` was implemented as a doubly-linked list, but named after an
abstract data type. This was inconsistent with `SinglyLinkedList`, which
can be used to implement an abstract data type, but is still named after
the implementation. Renaming `TailQueue` to `DoublyLinkedList` improves
consistency between the two type names, and should help discoverability.

`TailQueue` is now a deprecated alias of `DoublyLinkedList`.

Related to issues #1629 and #8233.
2023-08-27 20:57:46 -07:00
Nameless
b9fc0d2908
std.http: fix leaked connections (#16341)
The early return in pool release was causing leaked connections.
Closes #16282.
2023-07-07 20:08:19 +00:00
mlugg
f26dda2117 all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There
were a few exceptions which I had to manually fix:

* `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten
* `@truncate`'s fixup is incorrect for vectors
* Test cases are not formatted, and their error locations change
2023-06-24 16:56:39 -07:00
Piotr Sarna
438d680913 http: fix getting Transfer-Encoding value
The 'Content-Length' header was inspected by mistake,
which makes it effectively impossible to use chunked
Transfer-Encoding when using the http client.

Tested locally with a HTTP server - data is properly sent
with POST method and the proper encoding declared, after the fix.
2023-06-22 11:44:46 +03:00
Eric Joldasov
50339f595a all: zig fmt and rename "@XToY" to "@YFromX"
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-19 12:34:42 -07:00
Mizuochi Keita
729a051e9e std.http: Fix segfault while redirecting
Make to avoid releasing request's connection twice.
Change the `Request.connection` field optional. This field is null while the connection is released.

Fixes #15965
2023-06-17 21:58:33 -07:00
Xavier Bouchoux
67b3e07260 zlib: naming convention
Adress review comments from https://github.com/ziglang/zig/pull/13977
by using the same naming convention as zstd.

And by using `finish()` instead of `close()` for the finalisation of the compressed stream.
rationale:
  - it is not the same as how close() is usually used, since it must be called to flush and write the final bytes. And as such it may fail.
  - it is not the same `flush` in the deflate code, which allows to keep writting more bytes later, and doesn't write the final checksum.
  - it is the same name as used in the original zlib library (Z_FINISH)

Also, use a packed struct for the header, which seems a better fit.
2023-06-17 14:08:05 -07:00
Andrew Kelley
629f0d23b5
Merge pull request #15579 from squeek502/mem-delimiters
Split `std.mem.split` and `tokenize` into `sequence`, `any`, and `scalar` versions
2023-06-03 13:51:02 -07:00
Nameless
23ccff9cce
std.http.Server: collapse BufferedConnection into Connection 2023-06-01 13:44:00 -05:00
Nameless
0e5e6cb10c
std.http: add TlsAlert descriptions so that they can at least be viewed in err return traces 2023-06-01 13:43:55 -05:00
Nameless
8136123aa7
std.http.Client: collapse BufferedConnection into Connection 2023-06-01 13:43:23 -05:00
Ryan Liptak
2129f28953 Update all std.mem.split calls to their appropriate function
Everywhere that can now use `splitScalar` should get a nice little performance boost.
2023-05-13 13:45:05 -07:00
Ryan Liptak
815e53b147 Update all std.mem.tokenize calls to their appropriate function
Everywhere that can now use `tokenizeScalar` should get a nice little performance boost.
2023-05-13 13:45:04 -07:00
Nameless
9017d758b9
std.http: use larger read buffer to hit faster tls code 2023-05-06 21:35:17 -05:00
Nameless
1b3ebfefd8
fix keepalive and large buffered writes 2023-05-06 21:35:16 -05:00
Nameless
7b09629388
std.http: buffer writes 2023-05-06 21:35:16 -05:00
Nameless
71c228fe65
std.http: add simple standalone http tests, add state check for http server 2023-05-06 21:35:15 -05:00
Andrew Kelley
125221cce9 std: update to use @memcpy directly 2023-04-28 13:24:43 -07:00
Nameless
7285eedcd2 std.http: do -> wait, fix redirects 2023-04-26 00:02:55 -07:00
Andrew Kelley
1d1255b433
Merge pull request #15416 from squeek502/http-response-headers-undefined
std.http: Always initialize `response.headers` in Client.request
2023-04-24 15:15:17 -07:00
Ryan Liptak
0488c3cb52 std.http: Always initialize response.headers in Client.request
Before this change, if a request errored before getting its `response.headers` initialized, then it would attempt to `deinit` `response.headers` which would still be `undefined`. Since all locations that set `response.headers` use the same code, it can just be done upfront in `request` instead.

Closes #15380
2023-04-23 15:33:23 -07:00
Ryo Ota
06763c4c8c move the HTTP test to lib/std/http/test.zig 2023-04-21 09:51:23 +09:00
Ryo Ota
39c0c24b56 fix memory leaks and add an HTTP test 2023-04-21 02:35:38 +09:00
Ryo Ota
0f4f607814 fix http client build error 2023-04-20 22:19:00 +09: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
Nameless
96533b1289
std.http: very basic http client proxy 2023-04-17 19:14:48 -05:00
Nameless
2c492064fb
std.http: further curate error set, remove last_error 2023-04-17 19:14:48 -05:00
Nameless
038ed32cff
add explicit error union for Bundle.rescan and associated functions 2023-04-17 19:14:48 -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
8250a92544
update package manager to use req.do(), fix chunked trailer reading 2023-04-08 09:59:36 -05:00
Nameless
52c78f4974
fix bugs, waitForCompleteHead -> do, move redirecting to do instead of read
fix for 32bit arches

curate error sets for api facing functions, expose raw errors in client.last_error

fix bugged dependency loop, disable protocol tests (needs mocking)

add separate mutex for bundle rescan
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
Kotaro Inoue
9ecdcb8e30
Fix to use '/' for a empty path (#14884)
Signed-off-by: Kotaro Inoue <k.musaino@gmail.com>
2023-03-14 13:07:25 +02:00
Nameless
524e0cd987
std.http: rework connection pool into its own type 2023-03-09 14:55:31 -06:00
Nameless
634e715504
std.http: split Client's parts into their own files 2023-03-09 14:55:20 -06:00
Nameless
0a4130f364
std.http: handle relative redirects 2023-03-09 14:55:13 -06:00
Nameless
fd2f906d1e
std.http: handle compressed payloads 2023-03-09 14:54:26 -06:00
Nameless
afb26f4e6b
std.http: add connection pooling and make keep-alive requests by default 2023-03-09 14:54:23 -06:00
jim price
6ab04b5941 std.os: Allow write functions to return INVAL errors
In Linux when interacting with the virtual file system when writing
in invalid value to a file the OS will return errno 22 (INVAL).

Instead of triggering an unreachable, this change now returns a
newly introduced error.InvalidArgument.
2023-03-06 15:59:18 -05:00
Andrew Kelley
d56a65a8c4 std.http.Client: default to lazy root cert scanning
After this change, the system will be inspected for root certificates
only upon the first https request that actually occurs. This makes the
compiler no longer do SSL certificate scanning when running `zig build`
if no network requests are made.
2023-01-17 01:44:56 -05:00
Andrew Kelley
476cbe871a fix build failures on 32-bit arm due to u64/usize coercion 2023-01-11 15:39:49 -08:00
Andrew Kelley
c50f65304f std.http.Client: support the Reader interface 2023-01-11 15:39:48 -08:00
Andrew Kelley
aa87789c29 std.Uri: make scheme non-optional 2023-01-06 18:52:39 -07:00