TCP bytes in, an HTTP response out
Hearth is an HTTP server in Rust built from scratch on raw sockets, no hyper and no web framework. Every step from a TCP byte stream to a parsed request to a written response lives in code you can actually read.
this is a JS port of the exact parsing rules in src/request.rs, the same request line, header, and body logic Hearth runs on every real connection
A framework parses the request for you and never lets you see it happen. Hearth's parser is a few hundred lines you can read start to finish, and the demo above runs that exact logic in your browser.
Fast and production grade, and the request line, header, and connection handling are buried under async runtimes and layers of trait abstraction.
Read a fixed buffer and print it. No real parsing, no keep-alive, no body length handling, breaks on the first malformed request.
A real HTTP/1.1 parser and writer over std::net, threaded connection handling, a router, a static file server with path-traversal defense, all small enough to read in one sitting.
What Hearth actually does
Reads the request line, headers, and a Content-Length or chunked body straight off a TcpStream. A malformed request returns a typed parse error, never a panic.
Registers handlers by method and path, falls back to a static file handler, then 404. Exact match first, no regex, no magic.
Serves a directory with correct Content-Type by extension. Every resolved path is canonicalized and checked against the root, so a path-traversal attempt cannot escape it.
One thread per connection, a read timeout, hard caps on line and header size, and a caught panic per request. One bad connection never takes down the others.
hearth serve --dir ./public --port 8080 serves a directory over HTTP/1.1 with keep-alive, right away.
A built-in health check route, useful as a smoke test or a container liveness probe.
A built-in echo route that returns the request body back, useful for poking at the server with curl.
Unit tests for the parser, the response writer, the router, and path-traversal defense, plus an integration test that starts the real server and talks to it over a socket.
# start the server, then talk to it with curl (real captured output) $ hearth serve --dir ./public --port 8080 $ curl -si http://127.0.0.1:8080/health HTTP/1.1 200 OK Content-Type: application/json Content-Length: 15 Connection: keep-alive {"status":"ok"} $ curl -si -X POST -d hello http://127.0.0.1:8080/echo HTTP/1.1 200 OK Content-Type: application/x-www-form-urlencoded Content-Length: 5 Connection: keep-alive hello # a path-traversal attempt cannot escape the served root $ curl -si http://127.0.0.1:8080/../../etc/passwd HTTP/1.1 404 Not Found