Project 5: HTTP/1.1 Client (From Scratch)
A command-line HTTP client that can fetch web pages, submit forms, and download files—implementing HTTP/1.1 from raw sockets, including chunked transfer encoding and keep-alive connections.
Quick Reference
| Attribute | Value |
|---|---|
| Primary Language | C++ |
| Alternative Languages | Rust, Go, Python |
| Difficulty | Level 2: Intermediate |
| Time Estimate | 1-2 weeks |
| Knowledge Area | HTTP Protocol, Text Parsing, Keep-Alive |
| Tooling | curl replacement |
| Prerequisites | Project 2, string parsing skills |
What You Will Build
A command-line HTTP client that can fetch web pages, submit forms, and download files—implementing HTTP/1.1 from raw sockets, including chunked transfer encoding and keep-alive connections.
Why It Matters
This project builds core skills that appear repeatedly in real-world systems and tooling.
Core Challenges
- Parsing HTTP response headers → maps to line-by-line reading, header field extraction
- Determining response body length → maps to Content-Length vs chunked vs connection close
- Implementing chunked transfer decoding → maps to state machine parsing
- Connection keep-alive → maps to reusing sockets, connection pooling
Key Concepts
- HTTP/1.1 Protocol: RFC 7230-7235 (or RFC 2616 for simpler overview)
- Chunked Transfer Encoding: “HTTP: The Definitive Guide” Chapter 15 - Gourley
- Connection Management: “HTTP: The Definitive Guide” Chapter 4 - Gourley
- URL Parsing: RFC 3986
Real-World Outcome
$ ./httpclient https://httpbin.org/get
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 256
{
"args": {},
"headers": {
"Host": "httpbin.org",
"User-Agent": "MyHttpClient/1.0"
},
"origin": "1.2.3.4",
"url": "https://httpbin.org/get"
}
$ ./httpclient -X POST -d "name=test" https://httpbin.org/post
HTTP/1.1 200 OK
...
$ ./httpclient -o image.png https://example.com/image.png
Downloaded 45,234 bytes to image.png
$ ./httpclient -v https://example.com
> GET / HTTP/1.1
> Host: example.com
> User-Agent: MyHttpClient/1.0
> Connection: keep-alive
>
< HTTP/1.1 200 OK
< Content-Type: text/html
< Transfer-Encoding: chunked
<
<!DOCTYPE html>...
Implementation Guide
- Reproduce the simplest happy-path scenario.
- Build the smallest working version of the core feature.
- Add input validation and error handling.
- Add instrumentation/logging to confirm behavior.
- Refactor into clean modules with tests.
Milestones
- Milestone 1: Minimal working program that runs end-to-end.
- Milestone 2: Correct outputs for typical inputs.
- Milestone 3: Robust handling of edge cases.
- Milestone 4: Clean structure and documented usage.
Validation Checklist
- Output matches the real-world outcome example
- Handles invalid inputs safely
- Provides clear errors and exit codes
- Repeatable results across runs
References
- Main guide:
LEARN_CPP_NETWORK_PROGRAMMING.md - “HTTP: The Definitive Guide” by David Gourley