Commit 2bb396c
feat(zig-ffi): HTTP server primitives for OikosBot webhook receiver
Adds a synchronous, single-threaded HTTP/1.1 server FFI surface for
sitting behind a TLS reverse proxy (Caddy / nginx). Intended use:
the OikosBot links libgateway.so alongside libhpm_crypto.so and
composes them — no router, no TLS, no concurrency primitives here.
Why this repo: the user-elected home for HTTP server primitives,
matching the repo's HTTP-domain identity (verb governance is the
Elixir layer; this is the protocol-primitive layer alongside the
existing gRPC / GraphQL parsers).
New Zig exports (libgateway.so):
- hpm_http_server_listen / _port / _free / _accept
- hpm_http_request_method / _path / _header / _body / _respond / _free
Implementation notes:
- Heap-allocated RequestCtx holds the connection + IO buffers + the
std.http.Server + parsed std.http.Server.Request, so inner Reader /
Writer pointer addresses stay stable for the lifetime of the request.
- Headers parsed via std.http.Server's HeaderIterator with
case-insensitive name match.
- Method enum ordinal matches std.http.Method directly (GET=0..PATCH=8).
- Body capped at 1 MiB; content-length-driven read; idempotent.
- Connection always closes after respond (keep_alive=false) — keeps
the surface narrow for v1.
Idris2 ABI:
- New src/abi/HttpServer.idr with %foreign declarations and safe
wrappers mirroring the Zig exports. gateway.ipkg updated.
Tests:
- 15/15 main module tests pass (zig test src/main.zig -lc):
GET / POST + body / header lookup / header-absent / path size-query /
extra response headers / arbitrary status / method ordinals / null req
safety / listen failure paths / port introspection.
Pre-existing build hygiene fixes (latent under Zig 0.15.2):
- Handle: opaque → struct (Zig 0.15 forbids fields on opaque {}).
- Callback callconv: .C → .c (rename in Zig 0.15).
Unrelated red test: ffi/zig/grpc/parser.zig::"parse gRPC frame header"
fails because the test fixture isn't a valid HTTP/2 HEADERS frame.
Pre-existing on main; not addressed here.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 385ccf7 commit 2bb396c
5 files changed
Lines changed: 755 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
32 | 57 | | |
33 | 58 | | |
34 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
48 | 54 | | |
49 | | - | |
50 | 55 | | |
51 | | - | |
| 56 | + | |
| 57 | + | |
52 | 58 | | |
0 commit comments