This project implements a minimal HTTP/1.1 server in Go without using net/http.
It handles raw TCP connections, manually parses HTTP requests, and supports file serving, echo endpoints, and persistent connections.
- Raw TCP-based HTTP/1.1 implementation
- Persistent connections (keep-alive by default)
- Concurrent handling via goroutines
- Endpoints:
GET /— simple OK responseGET /echo/{msg}— returns plain textGET /user-agent— returns client's User-Agent headerGET /files/{filename}— serves files from a directoryPOST /files/{filename}— writes request body to a file
- Automatic
Content-Length,Content-Type, andConnectionheaders - Graceful handling of
Connection: close
Start the server:
go run main.go --directory ./files/The server listens on:
0.0.0.0:4221Example Requests Echo:
curl http://localhost:4221/echo/helloUser-Agent:curl http://localhost:4221/user-agent -H "User-Agent: test-agent"
Serve a File:
echo -n "Hello" > files/foo.txt
curl http://localhost:4221/files/foo.txtUpload a File (POST):
curl -X POST --data "12345" http://localhost:4221/files/newfile- Uses net.Listen and conn.Read to accept raw TCP requests
- Splits HTTP request into request line, headers, and body
- Processes multiple requests per connection (HTTP/1.1) 4.Routes requests using manual string parsing
- Sends fully manual HTTP responses:
Status Line
Headers
Body