Hearth logo

TCP bytes in, an HTTP response out

The server that shows
you the whole path.

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.

Try the parser in your browser View on GitHub

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

How to use this playground
Pick a sample request from the chips, or type a raw HTTP/1.1 request into the box yourself, then hit Parse. Hearth breaks it into a method, path, query, version, headers, and body, exactly the way the Rust server does off a socket. Try the malformed samples (no leading slash, bad version) to see the parser reject them with a typed error instead of crashing. It runs the same parsing rules as src/request.rs, ported to JavaScript.

Most servers hide the protocol. Hearth shows it.

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.

How it differs

hyper, actix-web

Fast and production grade, and the request line, header, and connection handling are buried under async runtimes and layers of trait abstraction.

Toy socket examples

Read a fixed buffer and print it. No real parsing, no keep-alive, no body length handling, breaks on the first malformed request.

Hearth

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

Four pieces, each one you can point at.

parser

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.

router

Registers handlers by method and path, falls back to a static file handler, then 404. Exact match first, no regex, no magic.

static files

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.

server

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.

A CLI, not a library you have to wire up.

hearth serve

hearth serve --dir ./public --port 8080 serves a directory over HTTP/1.1 with keep-alive, right away.

/health

A built-in health check route, useful as a smoke test or a container liveness probe.

/echo

A built-in echo route that returns the request body back, useful for poking at the server with curl.

cargo test

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