Packages
A Muro HTTP/1.1 library. The books and the C host dispatch to a handler. The challenge server is an example.
Current section
Files
Jump to
Current section
Files
README.md
<table>
<tr>
<td align="center">
<a href="https://github.com/murolang/muro-http"><img src="assets/muro-http-logo.png" alt="muro-http" width="140"></a>
</td>
<td>
<h3>An HTTP/1.1 core written in muro.<br>Checked, then served from C.</h3>
<a href="https://github.com/murolang/muro-http/actions/workflows/muro.yml"><img src="https://img.shields.io/github/actions/workflow/status/murolang/muro-http/muro.yml?branch=main&style=flat-square&label=ci&labelColor=111111&color=e8e8e8" alt="CI"></a>
<a href="https://hex.pm/packages/muro"><img src="https://img.shields.io/badge/muro-0.22.72-e8e8e8?style=flat-square&labelColor=111111" alt="muro 0.22.72"></a>
</td>
</tr>
</table>
# muro-http
`muro-http` is an HTTP/1.1 core written in muro and served from C.
The books classify the request, step the connection, admit work, and
render the response bytes. A C host owns the sockets and dispatches
each accepted request to a handler. This repository is a separate
library, version `0.1.0`; it is not part of muro's standard
library and it is not a book inside [murolang/muro](https://github.com/murolang/muro).
It pins muro `0.22.72` (`{:muro, "~> 0.22.72"}` in `mix.exs`,
`muro: "0.22.72"` in `muro.exs`). That release is on Hex.
`mix deps.get` resolves it, and `mix.lock` names Hex `0.22.72`.
The committed modules were generated by that compiler. There is
no Hex publish of this library.
## Quick start
Build the hello server and listen on `127.0.0.1:8080`:
```sh
git clone https://github.com/murolang/muro-http.git
cd muro-http
make c/muro-hello
./c/muro-hello --bind 127.0.0.1 --port 8080
```
The process prints `listening 127.0.0.1 8080`. In another terminal:
```sh
curl -i http://127.0.0.1:8080/
```
`GET` any path returns `hello\n` with `Content-Type: text/plain`.
`POST /` returns that same static `hello\n`. Any other `POST` path,
such as `POST /echo`, echoes the body. `PUT`, `DELETE`, `OPTIONS`,
`PATCH`, and `HEAD` reach the handler and get 405. Unknown methods
(`TRACE`, lowercase `get`, and the rest) are 501 from the host and
do not reach the handler. SIGINT and SIGTERM drain in-flight
requests and exit 0.
`./c/muro-hello --help` lists the flags. Defaults are bind
`127.0.0.1`, port 8080, 1 worker, 128 connections, 5 s idle, and an
8 MiB max body. `--workers N` is 1 through 64; the default does not
fork. `--wait poll`, `kqueue`, or `epoll` selects the wait. The
default is kqueue on macOS, epoll on Linux, and `poll(2)` otherwise.
The same flags are also read from `MURO_HTTP_BIND`, `MURO_HTTP_PORT`,
`MURO_HTTP_WORKERS`, `MURO_HTTP_WAIT`, and the other `MURO_HTTP_*`
variables in `--help`.
`make` also builds `c/muro-httpd`, the challenge example (`GET /health`,
`GET /feed`, `POST /posts`, `POST /posts/:id/like`, SQLite, JWT), and
`c/muro-stream`, which pulls chunked and known-length bodies. Those
servers are documented in [docs/examples.md](docs/examples.md).
### A handler of your own
`c/muro_http.h` is the reusable server. The snippet below is a
simplified handler: it always returns `hello\n`. See
`examples/hello/hello.c` for the full program, including `POST` echo
and 405. The host parses the flags, and the handler fills the
response:
```c
#include "muro_http.h"
static int on_req(const MuroHttpRequest *req, MuroHttpResponse *resp, void *user) {
static const char type[] = "Content-Type: text/plain\r\n";
(void)req;
(void)user;
resp->status = 200;
resp->reason = "OK";
resp->reason_len = 2;
resp->headers = type;
resp->headers_len = sizeof type - 1;
resp->body = (const uint8_t *)"hello\n";
resp->body_len = 6;
return 0;
}
int main(int argc, char **argv) {
MuroHttpConfig cfg;
int rc;
muro_http_config_init(&cfg);
cfg.name = "muro-hello";
rc = muro_http_config_parse(&cfg, argc, argv);
if (rc > 0) return 0;
if (rc < 0) return 2;
rc = muro_http_serve(&cfg, on_req, NULL);
if (rc == -2) return 2;
return rc == 0 ? 0 : 1;
}
```
Return 0 to send `resp`. Request slices point at the receive
buffer, which stays live until the host has framed the response.
A pointer into the handler's stack does not. The host writes
`Date`, `Connection`, and `Content-Length` (or `Transfer-Encoding`)
itself. Link the program the way `Makefile` builds `c/muro-hello`.
The books and their ExUnit tests also live in this repository
(`priv/muro/http/`, `lib/muro_http/`, `mix test`). The server you
run is the C host.
### Tests
```sh
make c-check
make c-conformance
```
`make c-check` compiles with `-Wall -Wextra -Werror -std=c11 -O2`
and runs the C drivers. `make c-conformance` runs
`c/test_conformance.py` against `c/muro-hello`. Book type-checking,
emit comparison, and `mix test` are in
[docs/check.md](docs/check.md).
## Performance
Loopback HTTP/1.1 on omarzo, 23 November 2026. Intel Core
i7-7820HQ, 4 cores / 8 hardware threads, governor `powersave`.
The tool is `bench/loadgen`. The body is `hello\n` (6 bytes) with
`Content-Type: text/plain`. No TLS. Each cell is a discarded
2-second warmup and three 5-second runs; the number is the median
req/s. Loadgen is pinned `taskset -c 4-7`. One worker uses
`taskset -c 0`. Four workers use `taskset -c 0-3`. Linux wait is
`--wait epoll`. Builds use the repo default `OPT=-O2`. Every cell
had 0 errors and 0 non-2xx.
Headline, 4 workers, keepalive, GET, c=128. p50 and p99 are from
the median run:
| server | req/s | p50 µs | p99 µs |
| --- | --- | --- | --- |
| muro-http | 236,145 | 526 | 1127 |
| nginx 1.30.7 | 221,140 | 560 | 941 |
| h2o 2.3.0-DEV | 243,011 | 505 | 1128 |
That matrix is about 7% ahead of nginx and about 3% behind h2o.
The same muro-http binary sat at 242,880 req/s on a quieter sitting.
Treat the headline as a band around 236–243k.
Keep-alive GET, median req/s:
| workers | c | muro-http | nginx | h2o |
| --- | --- | --- | --- | --- |
| 1 | 32 | 89,325 | 83,236 | 101,715 |
| 1 | 128 | 87,243 | 82,815 | 92,245 |
| 4 | 32 | 237,252 | 221,499 | 241,049 |
| 4 | 128 | 236,145 | 221,140 | 243,011 |
The verified `step_book` path (`c/muro-hello-book`) is at parity
with handwritten C on the same keep-alive GET `/`, c=128, 4-worker
setup, measured on omarzo on 1 December 2026 (27 runs, 0 errors).
71/71 conformance on both binaries. Details are in
[bench/NOTES.md](bench/NOTES.md).
| server | req/s | p50 µs | p99 µs | vs C |
| --- | --- | --- | --- | --- |
| handwritten C (`muro-hello`) | 229,371 | 515 | 1151 | 1.000× |
| `step_book` (hoist + memo) | 229,671 | 505 | 1097 | 1.001× |
| `step_book` without the memo | 208,601 | 574 | 1223 | 0.909× |
The full write-up, close-mode cells, earlier passes, and the morning
matrix that also measured Go net/http (on the tree before these
speedups; Go was not re-run later) are in:
- [bench/perf3-2026-11-23.md](bench/perf3-2026-11-23.md) — this table
- [bench/perf2-2026-11-23.md](bench/perf2-2026-11-23.md)
- [bench/perf-2026-11-23.md](bench/perf-2026-11-23.md)
- [bench/compare-2026-11-23.md](bench/compare-2026-11-23.md) — includes Go
## What is verified
The HTTP/1.1 decisions live in muro books under `priv/muro/http/`.
`mix muro.gen --check` type-checks each book and checks that the
committed C, Elixir, and ExUnit files still match a fresh emit.
`mix test` runs the Elixir suite. `make c-check` runs the C drivers.
`make c-conformance` runs the HTTP/1.1 suite against `c/muro-hello`.
CI also runs `make c-sanitize` (ASan and UBSan) and
`make fuzz-smoke`. The macOS job runs `make c-check` with kqueue
and does not run the conformance suite, which starts the hello
server with `--wait epoll`.
The books choose classify, keep versus close, admission, and the
response bytes, including `Date` and the 400, 413, 417, 500, and
501 copies. The C host owns the sockets, the buffers, the clock,
and the wait. The backend contract is
[docs/protocol-backend.md](docs/protocol-backend.md).
## Docs and layout
| Doc | What it covers |
| --- | --- |
| [docs/http-core.md](docs/http-core.md) | Request classifier, connection step, session stepper |
| [docs/host.md](docs/host.md) | Host loop, reply order, writing a backend, limits |
| [docs/examples.md](docs/examples.md) | Hello, stream, and challenge servers |
| [docs/emitted.md](docs/emitted.md) | What muro emits and what is hand-written |
| [docs/check.md](docs/check.md) | Book checks and C drivers |
| [docs/protocol-backend.md](docs/protocol-backend.md) | Step/backend contract |
```
priv/muro/http/ muro books
c/muro_http.h reusable C server API
c/host.c, c/step.c socket adapter and one-connection step
c/generated/ committed C emit
examples/hello c/muro-hello
examples/stream c/muro-stream
examples/challenge c/muro-httpd
examples/adapter socket-free backend (`c/test_step`)
lib/, test/ Elixir modules and ExUnit
bench/ recorded comparisons
```
License is MIT (`LICENSE`).