Master the fundamental concepts of protocol implementation through this focused micro-challenge.
HTTP/1.1 rides on TCP port 80 (or 443 with TLS). A typical request looks like:
cLoading…
The blank line after headers marks the end of the header block. POST/PUT requests add a body after that line.
The server replies with a status line and headers:
cLoading…
Key headers for a file server:
Host: required for virtual hostingContent-Length: exact body size in bytesConnection: keep-alive or closeA minimal server reads the request line with recv(), splits method, URI, and version, maps /index.html to a filesystem path, and writes the status line plus headers before streaming the file body. No framework handles framing for you at this level.
This task asks you to parse the request line, map the URI to a file, and construct a response with raw sockets. nginx does this same byte-level parsing on port 80 and 443, and mismatched Content-Length handling between a server and an upstream proxy is the root cause of real HTTP request-smuggling CVEs. RFC 9112 governs every header and status line you construct in this exercise.
Write a C program that implements a simple HTTP/1.1 server. The server should parse incoming requests and serve a static file or a directory listing.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github