http-from-scratch: one HTTP/1.1 server in Rust, built twice
Most developers use HTTP through a framework, which hides how requests are separated from a stream of bytes. http-from-scratch makes those mechanics visible: it is a learning project implementing an HTTP/1.1 server in Rust, not a production server. It has an incremental parser, response writer, routes, and a shared connection step. The parser waits until a complete request head and body arrive, then reports how many bytes it consumed. The server serves files under a chosen root, echoes POST bodies at /echo, and streams a chunked response at /chunked. There are two ways to run it: a standard-library server with a hand-built thread pool, or a Tokio server. Both use the same parser, handler, and connection state machine. That shared design lets learners compare how bytes arrive without changing the HTTP logic, and test both servers with the same curl commands.
What is http-from-scratch, and what does its HTTP/1.1 server do?
Most developers use HTTP through a framework, which hides how requests are separated from a stream of bytes. http-from-scratch makes those mechanics visible: it is a learning project implementing an HTTP/1.1 server in Rust, not a production server.
It has an incremental parser, response writer, routes, and a shared connection step. The parser waits until a complete request head and body arrive, then reports how many bytes it consumed. The server serves files under a chosen root, echoes POST bodies at /echo, and streams a chunked response at /chunked.
There are two ways to run it: a standard-library server with a hand-built thread pool, or a Tokio server. Both use the same parser, handler, and connection state machine. That shared design lets learners compare how bytes arrive without changing the HTTP logic, and test both servers with the same curl commands.
Why did the author build the server twice, and what differs between the Rust thread-pool version and the Tokio version?
The author built the server twice to demonstrate that HTTP parsing and handling do not need to depend on how network bytes arrive. Keeping those parts independent matters because the same logic can work with two different I/O models and can be tested without opening sockets.
In the standard-library version, TcpListener and a hand-made fixed thread pool handle connections. The Tokio version uses Tokio for its read loop. Both versions call the same connection step, which parses a request, handles it, serializes a response, and decides whether to keep the connection open.
The article says the parser, handler, and connection state machine contain no I/O or async code. Only the movement of bytes differs. The author suggests running the same four curl commands against both servers: their answers should match because they share the same parser and handler. The comparison makes the separation practical, not just a design claim.
How large a request body can the server accept?
There is no stated number for the largest request body the server accepts. The article says the parser enforces size limits and responds with 413 when a limit is exceeded, but it does not give the limit value or describe how that value is set.
The parser supports request bodies framed with Content-Length or Transfer-Encoding: chunked. For example, the article's curl commands include a chunked POST to /echo, which exercises the chunked request decoder. That demonstrates a supported body format, not a maximum body size.
So the article alone cannot establish a byte count for the upper limit. The 413 response indicates that oversized requests can be rejected, but no exact threshold is provided. Anyone needing the server's actual maximum would need details beyond this description, such as the relevant implementation settings; the article does not specify them.
What can happen if a proxy and a server disagree about where a request ends because of Content-Length and Transfer-Encoding?
Content-Length and Transfer-Encoding can describe different ways to determine where a request body ends. If a proxy trusts one header while the server behind it trusts the other, they may split the same byte stream at different places. That disagreement matters because the two systems no longer agree on which bytes belong to which request.
The article describes the consequence: an attacker can hide a second request inside the first. This is request smuggling. The server's parser rejects requests that contain both Content-Length and Transfer-Encoding, and also rejects conflicting Content-Length values. These checks prevent the parser from accepting ambiguous framing.
The project treats this as a small validation check with a large security effect. The lesson applies beyond this learning server: components that interpret request boundaries need consistent rules. Rejecting ambiguous input avoids letting different components assign different meanings to the same bytes.
Why can a keep-alive connection tie up a thread in the standard-library server, and how can that affect other clients?
Keep-alive lets a connection remain open after a response, so the server can use it for more requests. In the standard-library version, that connection occupies a pool thread until it closes or reaches the idle timeout. The article sets that timeout to five seconds.
The thread is tied up because the standard server's connection loop waits for further activity on that connection. A fixed pool has only a limited number of workers, so threads waiting on idle connections cannot work on other connections at that time. If many connections stay open, fewer workers remain available for new work.
The article points to this cost as a lesson of implementing the thread model directly, and says seeing it in code makes the case for async I/O clearer. It does not quantify effects on other clients, but fewer available workers can mean they must wait for a worker to become free.
What does HTTP request framing mean, and why must a server find message boundaries in a TCP byte stream?
HTTP request framing means determining which bytes make up one complete request, including its head and body. This matters because TCP provides a stream rather than separate message-sized deliveries. A server cannot assume that one read equals one request.
A read might contain only part of a request line, or one full request plus part of the next. The project's parser accepts the bytes received so far and returns incomplete until a full request is available. Once complete, it reports how many bytes it consumed, leaving any following pipelined request in the buffer.
The article describes a unit test that captures the rule: every prefix of a valid request is incomplete, not an error. This incremental contract lets the server handle data arriving in pieces without mistaking a partial message for malformed input. Correct framing also matters for security, since conflicting interpretations of message boundaries can enable request smuggling.
How does async I/O let a server handle connections without keeping one thread occupied while each connection waits for more bytes?
In general, async I/O lets a server suspend the work for a connection while it waits for network data. A worker can then run other ready tasks rather than sitting idle on that connection. This helps avoid dedicating one blocked thread to every connection that is waiting for more bytes.
The article presents a Tokio version alongside a standard-library version. Both use the same I/O-free parser, handler, and connection step; only the way bytes move differs. The standard version uses a hand-made thread pool, where an open keep-alive connection occupies a thread until it closes or idles out.
The article does not detail Tokio's scheduling or readiness mechanisms, so those details come from general knowledge of async I/O, not the project description. Its stated lesson is that seeing the thread cost in the standard server makes the case for async I/O clearer. The shared code also means the two approaches can be compared without changing request handling.
This brief was written by AI from the original reporting and checked by other models. Names, figures and quotes come from the source; read it for full context.
Read more in the JupiteX app
Pulse is free. New stories every 4 hours, each one broken into the questions that explain it.
Or read more news on the web