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 reads an HTTP/1.1 request from stdin in wire format (CRLF line endings) whose body uses chunked Transfer-Encoding, and decodes it per RFC 9112 section 7.1.
Input: a full request: request line, header lines, blank line, then a chunked body: one line per chunk holding the chunk size in hexadecimal (possibly followed by a ;extension that must be ignored), followed by exactly that many raw data bytes and a CRLF, terminated by a zero-size chunk.
Output:
body= followed by the concatenated decoded chunk data (raw bytes: a chunk's data may itself contain CR/LF, so read exactly the size, never line-by-line)chunks=N: number of non-empty chunkslength=N: total decoded body size in bytesExample: chunk sizes 4, 5, e;checksum=9f, 0 decode to Wikipedia in\n\nchunks.: note how the e chunk (14 bytes) spans what looks like two lines, which is why a naive line reader desyncs. No sockets needed: the request arrives on stdin.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it works