Master the fundamental concepts of protocol implementation through this focused micro-challenge.
HTTP/1.1 defaults to keep-alive: one TCP connection on port 80 serves multiple requests. For example, a browser fetches /index.html, then /style.css, then /logo.png over the same socket without repeating the three-way handshake.
The client must know where each response ends:
Content-Length: 1234 tells the client to read exactly 1234 bytesTransfer-Encoding: chunked is the alternative for dynamic contentEither side can terminate with Connection: close.
192.168.1.10:80Connection: keep-aliveContent-LengthConnection: close to endPipelining (sending multiple requests before reading responses) was part of HTTP/1.1 but rarely used in practice because head-of-line blocking on TCP made it risky. Modern browsers open several parallel connections to the same host on port 443 instead of pipelining on one socket.
This task requires you to handle multiple requests on one connection. The Slowloris attack from 2009 abused this lifecycle by opening many keep-alive connections and trickling headers slowly to exhaust server connection pools. Production configs like nginx's keepalive_timeout and Apache's KeepAliveTimeout tune the same Connection header behavior you implement here on port 80.
Write a C program that documents HTTP/1.1 persistent connections. Show a request/response sequence on the same socket, Content-Length parsing, and connection management.
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