DIR1 note inside
HTTP Server from Scratch
Reinventing the wheel to learn how the road works. Building a compliant HTTP/1.1 server using only Rust std::net.
"Imagine not using AI in the Lord's year 2025..." — ThePrimeagen
The Objective
To build a fully functional HTTP/1.1 server without touching Actix, Axum, or Tokio. We are going raw std::net::TcpListener to understand the magic behind the frameworks.
This project follows The Codeholic / ThePrimeagen's "From TCP to HTTP" course, but translated from Go to Rust.
Specs:
- Lang: Rust 🦀
- Crates Allowed:
stdonly (maybeanyhowif I get lazy) - Protocol: HTTP/1.1 (RFC 9110 / 9112)
Implementation Roadmap
Phase 1: Setup
Before we speak HTTP, we must master the socket.
- Ch 1: HTTP Streams
- Goal: Create a continuous read loop that doesn't panic on empty bytes.
- Ch 2: TCP
- Goal: Bind
std::net::TcpListenerto port 4221 and handle the 3-way handshake.
- Goal: Bind
Phase 2: Parsing Inbound (Request)
Turning raw bytes into a strongly typed Rust struct.
- Ch 3: Requests
- Goal: Define the
Requeststruct and basic lifecycle.
- Goal: Define the
- Ch 4: Request Lines
- Goal: Parse the "start-line":
METHOD URI VERSION(e.g.,GET /index.html HTTP/1.1).
- Goal: Parse the "start-line":
- Ch 5: HTTP Headers
- Goal: Parse
Key: Valuepairs into aHashMap, handling the\r\ndelimiters.
- Goal: Parse
- Ch 6: HTTP Body
- Goal: Read the payload based on
Content-Length(avoiding the infinite hang).
- Goal: Read the payload based on
Phase 3: Parsing Outbound (Response)
Sending data back without breaking the client.
- Ch 7: HTTP Responses
- Goal: Implement a
Responsebuilder that formats the status line and headers correctly.
- Goal: Implement a
Phase 4: Advanced Delivery
The complex stuff that makes the internet work.
- Ch 8: Chunked Encoding
- Goal: Implement
Transfer-Encoding: chunkedfor streaming data of unknown length.
- Goal: Implement
- Ch 9: Binary Data
- Goal: Serving images and files (handling raw
[u8]vsString).
- Goal: Serving images and files (handling raw