{"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.7.0","deps":[],"features":{},"cksum":"sha256:89aa28324d9bbdbda0bf03d6e06fb8e3a429b95d1e73457191caba5861297911","sig":"ed25519:4acdaaf005dfedf38093ee4bb2c052653f65af806715a263b584b91eeca2aa92f97a7b9ce56660fffb4f9fb75ed7481b330bea6ea85f6437e20132f7d935fc0a","key_fp":"SHA256:QDgYk38yt+UbTDqWpi+aVd+Vkirhyd7m4y+5bVuNIpg","yanked":false,"edition":"2026","hew":">=0.10.0, <0.12.0","registry_sig":"ed25519:1d445d1d46ede2653ef00faec0a366a047efbf5168a2cfeda69f2c849f2fbccc74c345e71e61b369497de1b43266daa991638e6952947f9460926c49b21eed07","registry_key_fp":"SHA256:NR2yrof9/ZWkCWyhDODRU8Yvm9Lob/0yYVTdCKzMHb8","published_at":"2026-11-13T06:01:22.648Z","dl":"https://cdn.hewpkg.com/tarballs/hew/net/http/0.7.0.tar.zst"}}