{"metadata":{"name":"hew/net/http","vers":"0.7.1","description":"Actor-owned HTTP/1.1 server with typed errors and one-request handling","license":"MIT OR Apache-2.0","authors":["Hew Contributors"],"deps":[],"features":{},"keywords":["http","http1","server","actor","networking"],"repository":"https://github.com/hew-lang/ecosystem","edition":"2026","hew":">=0.10.0, <0.12.0","readme":"# hew.net.http\n\n`hew.net.http` is a small HTTP/1.1 server with actor-owned listener and\nconnection lifecycles plus typed errors. Each `accept_one` call waits for one\nrequest for up to 250 milliseconds; the package does not hide a loop or promise\nan unavailable request generator.\n\n```hew\nimport hew.net.http;\n\nfn main() {\n    let server = spawn http.Server { addr: \"127.0.0.1:8080\" };\n    var attempts_left = 120;\n    var served = false;\n    while attempts_left > 0 && !served {\n        attempts_left = attempts_left - 1;\n        match server.accept_one() {\n            .Ok(request) => {\n                println(f\"{request.method()} {request.path()}\");\n                match server.respond_text(200, \"Hello from Hew!\\n\") {\n                    .Ok(_) => {}\n                    .Err(.Failed(error)) => println(http.error_message(error)),\n                    .Err(_) => println(\"HTTP server actor stopped before replying\"),\n                }\n                served = true;\n            }\n            // An idle quarter second is the documented outcome of\n            // accept_one(), so it is a retry rather than a failure.\n            .Err(.Failed(.Accept(_))) => {}\n            .Err(.Failed(error)) => {\n                println(http.error_message(error));\n                served = true;\n            }\n            .Err(_) => {\n                println(\"HTTP server actor stopped before replying\");\n                served = true;\n            }\n        }\n    }\n    stop(server);\n    stopped(server);\n}\n```\n\nThe retry loop is not ceremony: without it the 250-millisecond timeout fires\nbefore anyone can send a request, so the only outcome a reader could ever\nobserve is the `Accept` error.\n\nThe checked example at [`examples/hello.hew`](examples/hello.hew) is this\nprogram with the loop moved into `serve_one`, which returns the request line,\nplus the listening banner and a message for the case where the thirty seconds\nelapse unused. Its test serves one request while\n`std.net.http.client` sends `GET /hello`, then checks the body the client\nreceived and the request line the server saw. Run it from the ecosystem\ncheckout:\n\n```sh\nhew run --pkg-path . net/http/examples/hello.hew\n```\n\nthen, from a second terminal within those thirty seconds:\n\n```sh\ncurl http://127.0.0.1:8080/hello\n```\n\nThe server prints `GET /hello` and exits; `curl` prints `Hello from Hew!`. With\nno request at all it prints `no request arrived within 30 seconds` and still\nexits successfully.\n\n`server.local_addr()` binds the actor's listener if needed and returns its\nactual local address. A successful call establishes readiness without\naccepting a request. For an OS-assigned port, spawn with `addr: \"127.0.0.1:0\"`\nand use the address it returns. Later calls and `accept_one()` use that same\nowned listener; a bind failure returns `HttpError.Listen`. The example's test\nuses this readiness call and an assigned port, so it does not depend on port\n8080 being free. Its checked client retains HTTP status and transport-error\ndetails when a request fails.\n\nEvery `Server` method that can fail is declared `-> T fails HttpError`, so a\ncall replies `Result<T, ActorError<HttpError>>`: the handler's error arrives as\n`.Err(.Failed(error))`, and any other `.Err` means the actor did not reply (for\nexample `.Dead` after `stop`). The actor retains\neach accepted connection until a response method or actor stop releases it.\nIt also releases listener and request handles from its stop hook, including\nfailure and caller-abandonment paths.\n\nOnly one request may be pending in the actor at a time. Call one of the\nresponse methods before accepting another request. Stop the server when it is\ndone handling requests. An idle\n`accept_one()` returns an `Accept` error after 250 milliseconds, which keeps a\nqueued actor stop from being trapped behind a blocking socket call;\nservers normally retry `accept_one()` after that timeout.\n\nHeader and response methods return `HttpError.NoPending` when the server is\nopen but no request is awaiting a response.\n\n`server.header(name)` performs a case-insensitive lookup on the pending\nrequest and fails with `HttpError.MissingHeader(name)` when the header is\nabsent. An empty header value is therefore distinct from a missing header.\nIncoming HTTP/1.1 requests must contain exactly one valid `Host` header.\nResponse methods accept final status codes from 200 through 599; informational\nresponses are rejected because this one-response API cannot send the required\nlater final response.\n\nStrings cross the native ABI as managed Hew string values carrying an exact\nbyte length, so embedded NUL bytes survive in both directions: a request body\ncontaining NUL is delivered whole, and a response body containing NUL is\ntransmitted without truncation. HTTP header values containing NUL are still\nrejected, incoming and outgoing, because NUL is not a valid HTTP field value\ncharacter.\n\n`server.url_decode(text)` decodes percent escapes as UTF-8 and converts\n`+` to a space. Malformed escapes and decoded bytes that are not UTF-8 return\n`HttpError.Decode`. `server.form_value(body, key)` applies the same\nstrict decoding to URL-encoded form fields; a missing key returns\n`HttpError.MissingFormField` rather than an empty-string sentinel.\n"},"version":{"name":"hew/net/http","vers":"0.1.0","deps":[],"features":{},"cksum":"sha256:4a9cd2ece40971f53769d6a41de9b8d1d50a6b05713d2a4ba4b9068137b72085","sig":"ed25519:7e87a1567c2626c54d80be36d0ce647a95503b3dddee2f22bf4bbcf3773e6de72e2b792b898323e6ff04969eab20be355cfd2ef7b0ef040b849026743419b701","key_fp":"SHA256:3njv78NJD/NTkV83eJ86yfrXqpu+l652GAjPzB/Grp0","yanked":false,"registry_sig":"ed25519:7745ddeb0de8791f221c5711b08cc55bc27cbbb1f8393df4514a889c87b0f167365b7cd9be61656555a0239a25dc9f4ba857e3cb299f52d73c834e12fd7c8a00","registry_key_fp":"SHA256:NR2yrof9/ZWkCWyhDODRU8Yvm9Lob/0yYVTdCKzMHb8","published_at":"2026-03-12T21:10:56.856Z","dl":"https://cdn.hewpkg.com/tarballs/hew/net/http/0.1.0.tar.zst"}}