Project 3: HTTP Server from Scratch
An HTTP/1.1 server using only Go’s
netpackage (notnet/http), supporting GET/POST, headers, static files, and keep-alive connections.
Quick Reference
| Attribute | Value |
|---|---|
| Primary Language | Go |
| Alternative Languages | C, Rust, Zig |
| Difficulty | Level 3: Advanced |
| Time Estimate | 2-3 weeks |
| Knowledge Area | Networking, HTTP Protocol, TCP Sockets |
| Tooling | None (net package only) |
| Prerequisites | Completed Projects 1-2. Understand goroutines basics. Read about HTTP/1.1 request/response format. |
What You Will Build
An HTTP/1.1 server using only Go’s net package (not net/http), supporting GET/POST, headers, static files, and keep-alive connections.
Why It Matters
This project builds core skills that appear repeatedly in real-world systems and tooling.
Core Challenges
- Accepting TCP connections → maps to net.Listen and net.Conn
- Parsing HTTP requests → maps to bufio.Reader and string parsing
- Handling concurrent connections → maps to goroutines and connection pools
- Implementing keep-alive → maps to connection lifecycle management
Key Concepts
- TCP in Go: “Network Programming with Go” Ch. 3 - Jan Newmarch
- HTTP/1.1 spec: RFC 7230-7235 (sections on message format)
- Goroutines for connections: “Concurrency in Go” Ch. 3 - Katherine Cox-Buday
- Buffer management: “The Go Programming Language” Ch. 7.6 - Donovan & Kernighan
Real-World Outcome
$ ./httpserver --port 8080 --root ./public
Server listening on :8080
# In another terminal:
$ curl -v http://localhost:8080/index.html
> GET /index.html HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.0.1
>
< HTTP/1.1 200 OK
< Content-Type: text/html
< Content-Length: 156
< Connection: keep-alive
<
<!DOCTYPE html>
<html>...
$ curl -X POST http://localhost:8080/echo -d '{"message": "hello"}'
{"received": {"message": "hello"}}
$ curl http://localhost:8080/not-found
HTTP/1.1 404 Not Found
# Your server logs:
[2025-01-10 14:32:01] 192.168.1.5:52341 - GET /index.html - 200 - 2ms
[2025-01-10 14:32:05] 192.168.1.5:52341 - POST /echo - 200 - 1ms
[2025-01-10 14:32:08] 192.168.1.5:52342 - GET /not-found - 404 - 0ms
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_GO_DEEP_DIVE.md - “Network Programming with Go” by Jan Newmarch