aboutsummaryrefslogtreecommitdiff
path: root/lib/std/http/protocol.zig
AgeCommit message (Collapse)Author
2025-08-07std.http: rework for new std.Io APIAndrew Kelley
2025-07-07std.io: deprecated Reader/Writer; introduce new APIAndrew Kelley
2025-01-16x86_64: looped instructionsJacob Young
2024-11-07std.crypto.tls: implement TLSv1.2Jacob Young
2024-02-23std.http.Server: expose arbitrary HTTP headersAndrew Kelley
Ultimate flexibility, just be sure to destroy the correct amount of information when looking at them.
2024-02-23std.http.Server: reimplement chunked uploadingAndrew Kelley
* Uncouple std.http.ChunkParser from protocol.zig * Fix receiveHead not passing leftover buffer through the header parser. * Fix content-length read streaming This implementation handles the final chunk length correctly rather than "hoping" that the buffer already contains \r\n.
2024-02-23std.http.Server: rework the API entirelyAndrew Kelley
Mainly, this removes the poorly named `wait`, `send`, `finish` functions, which all operated on the same "Response" object, which was actually being used as the request. Now, it looks like this: 1. std.net.Server.accept() gives you a std.net.Server.Connection 2. std.http.Server.init() with the connection 3. Server.receiveHead() gives you a Request 4. Request.reader() gives you a body reader 5. Request.respond() is a one-shot, or Request.respondStreaming() creates a Response 6. Response.writer() gives you a body writer 7. Response.end() finishes the response; Response.endChunked() allows passing response trailers. In other words, the type system now guides the API user down the correct path. receiveHead allows extra bytes to be read into the read buffer, and then will reuse those bytes for the body or the next request upon connection reuse. respond(), the one-shot function, will send the entire response in one syscall. Streaming response bodies no longer wastefully wraps every call to write with a chunk header and trailer; instead it only sends the HTTP chunk wrapper when flushing. This means the user can still control when it happens but it also does not add unnecessary chunks. Empirically, in my example project that uses this API, the usage code is significantly less noisy, it has less error handling while handling errors more correctly, it's more obvious what is happening, and it is syscall-optimal. Additionally: * Uncouple std.http.HeadParser from protocol.zig * Delete std.Server.Connection; use std.net.Server.Connection instead. - The API user supplies the read buffer when initializing the http.Server, and it is used for the HTTP head as well as a buffer for reading the body into. * Replace and document the State enum. No longer is there both "start" and "first".
2024-02-23std.http: parser fixesAndrew Kelley
* add API for iterating over custom HTTP headers * remove `trailing` flag from std.http.Client.parse. Instead, simply don't call parse() for trailers. * fix the logic inside that parse() function. it was using wrong std.mem functions, ignoring malformed data, and returned errors on dead branches. * simplify logic inside wait() * fix HeadersParser not dropping the 2 read bytes of \r\n after a chunked transfer * move the trailers test to be a std lib unit test and make it pass
2024-02-23Revert "std.http: remove 'done' flag"Andrew Kelley
This reverts commit 42be972a72c86b32ad8403d082ab42763c6facec. Using a bit to distinguish between headers and trailers is fine. It was just named and documented poorly.
2024-02-23std.http: remove 'done' flagAndrew Kelley
This is a state machine that already has a `state` field. No need to additionally store "done" - it just makes things unnecessarily complicated and buggy.
2024-02-23std.http: remove the ability to heap-allocate headersAndrew Kelley
The buffer for HTTP headers is now always provided via a static buffer. As a consequence, OutOfMemory is no longer a member of the read() error set, and the API and implementation of Client and Server are simplified. error.HttpHeadersExceededSizeLimit is renamed to error.HttpHeadersOversize.
2024-01-18std.http.Client: read response messages with no length until eofNameless
2024-01-01Deprecate `suggestVectorSize` in favor of `suggestVectorLength`Carl Åstholm
The function returns the vector length, not the byte size of the vector or the bit size of individual elements. This distinction is very important and some usages of this function in the stdlib operated under these incorrect assumptions.
2023-11-19lib: correct unnecessary uses of 'var'mlugg
2023-11-03x86_64: fix std test failuresJacob Young
2023-10-31std.builtin.Endian: make the tags lower caseAndrew Kelley
Let's take this breaking change opportunity to fix the style of this enum.
2023-10-21std.http.Client: store *Connection instead of a pool node, buffer writesNameless
2023-10-13std.simd: return comptime_int from `suggestVectorSize`Veikka Tuominen
2023-08-29std.http: handle expect:100-continue and continue responsesNameless
2023-07-12Remove len parameter from splat in standard libantlilja
2023-06-24all: migrate code to new cast builtin syntaxmlugg
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-23std.http: fix the http.Client.wait() hanging when there is 1 more byte leftEd Yu
2023-06-16migration: std.math.{min, min3, max, max3} -> `@min` & `@max`r00ster91
2023-06-01std.http: add TlsAlert descriptions so that they can at least be viewed in ↵Nameless
err return traces
2023-06-01std.http.Client: collapse BufferedConnection into ConnectionNameless
2023-04-28std: update to use `@memcpy` directlyAndrew Kelley
2023-04-24fix HTTP server to handle a chunked transfer coding requestRyo Ota
2023-04-17std.http: very basic http client proxyNameless
2023-04-08std.http: reenable protocol read tests, add missing branch in findHeaders endNameless
2023-04-08std.http: add documentationNameless
2023-04-08fix bugs, waitForCompleteHead -> do, move redirecting to do instead of readNameless
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-08add buffering to connection instead of the http protocol, to allow passing ↵Nameless
through upgrades
2023-04-08std.http: add http serverNameless
* 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(); } } ```