feat: std.http handler carries an opaque ctx word (PLAN-HTTPZ A1 prep)

Server.init(cfg, handler, ctx); the handler signature gains a usize
third argument delivered verbatim per dispatch — typically a pointer
to the app's own state, since the server owns the call site. A bare
(req, resp) handler had no way to reach app state without globals.
examples/1633 pins the round trip.
This commit is contained in:
agra
2026-06-12 21:22:42 +03:00
parent 721793b4bf
commit 3a97019aa7
39 changed files with 10032 additions and 9872 deletions

View File

@@ -7,9 +7,11 @@
PORT :: 18933;
handler :: (req: *http.Request, resp: *http.Response) {
handler :: (req: *http.Request, resp: *http.Response, ctx: usize) {
if req.path == "/hello" {
resp.body = concat("hello ", req.method);
// the ctx word arrives verbatim (init passed 77)
if ctx != 77 { resp.status = 500; resp.body = "ctx lost"; }
return;
}
if req.path == "/echo" {
@@ -105,7 +107,7 @@ main :: () -> i32 {
request_count = 3,
max_conn = 8,
};
srv, se := http.Server.init(cfg, handler);
srv, se := http.Server.init(cfg, handler, 77);
if se { print("server init failed\n"); return 1; }
buf : [4096]u8 = ---;