HTTP Over TCP is a minimal HTTP/1.1 implementation written from scratch in Go, built directly on top of raw TCP sockets.
Instead of using Go’s built-in net/http package, this project manually handles:
- TCP connections
- Request parsing (request line, headers, body)
- Response writing (status line, headers, body, chunked encoding)
- Basic server abstraction similar to a mini framework
This project is designed for learning and experimentation with networking and HTTP internals.
-
Parse HTTP/1.1 request lines, headers, and body
-
Validate and manage headers
-
Response writer with:
- Status codes (
200,400,500, …) - Static file serving
- Streaming (chunked transfer encoding)
- Status codes (
-
Simple server abstraction (
server.Serve) -
Two runnable demos:
tcplistener: raw TCP listener that prints parsed requestshttpserver: a full HTTP server with routes
.
├── cmd/
│ ├── httpserver/ # Example HTTP server with routes & responses
│ │ └── main.go
│ └── tcplistener/ # Raw TCP listener that parses HTTP requests
│ └── main.go
│
├── internal/
│ ├── headers/ # Header parsing & management
│ │ ├── headers.go
│ │ └── headers_test.go
│ ├── request/ # HTTP request parsing state machine
│ │ ├── request.go
│ │ └── request_test.go
│ ├── response/ # HTTP response writer
│ │ └── response.go
│ └── server/ # Server abstraction (Serve, Close, etc.)
│ └── server.go
├── message.txt # Sample data for testing
└── Readme.md
git clone https://github.com/suhasdeveloper07/httpovertcp.git
cd httpovertcpThis simply prints the incoming HTTP request structure:
go run ./cmd/tcplistenerThen in another terminal:
curl -v http://localhost:42069/This version demonstrates actual responses:
go run ./cmd/httpserver/→ 200 OK HTML page/yourproblem→ 400 Bad Request/myporblem→ 500 Internal Server Error/video→ servesassets/vim.mp4/httpbin/stream/<n>→ streams data from httpbin.org
You can build custom handlers using server.Serve:
server, _ := server.Serve(42069, func(w *response.Writer, req *request.Request) {
body := []byte("Hello from custom handler!")
h := response.GetDefaultHeaders(len(body))
h.Replace("Content-Type", "text/plain")
w.WriteStatusLine(response.StatusOk)
w.WriteHeaders(*h)
w.WriteBody(body)
})
defer server.Close()This project is not meant for production use. Instead, it is a step-by-step exploration of how HTTP really works:
- From raw TCP streams → structured HTTP requests
- From status lines → full HTTP responses
- From simple listeners → a mini HTTP server
MIT License © 2025 suhasdeveloper07