A lightweight HTTP/1.1 server implementation built from scratch in Go, parsing TCP connections directly without using the standard net/http package.
- HTTP/1.1 Protocol Support: Handles request parsing, headers, and bodies
- Chunked Transfer Encoding: Supports streaming responses with trailers
- Custom Routes: Includes demo endpoints with different status codes
- Video Streaming: Serves video files with proper content types
- HTTP Proxying: Can proxy requests to external services (e.g., httpbin.org)
- Go 1.16 or higher
- Git (for cloning the repository)
# Clone the repository
git clone https://github.com/shv-ng/http-from-tcp
cd http-from-tcp
# Install dependencies
go mod download# Start the HTTP server
go run cmd/httpserver/main.goThe server will start on port 42069.
For debugging raw HTTP requests:
go run cmd/tcplistener/main.goOnce the server is running, you can make requests:
# Basic GET request
curl http://localhost:42069/
# Test error responses
curl http://localhost:42069/yourproblem # Returns 400
curl http://localhost:42069/myproblem # Returns 500
# Stream video content
curl http://localhost:42069/video
# Test chunked transfer encoding with trailers
curl http://localhost:42069/httpbin/stream/20 -v/- Returns a 200 OK response with HTML/yourproblem- Returns a 400 Bad Request/myproblem- Returns a 500 Internal Server Error/video- Streams a video file (requiresassets/vim.mp4)/httpbin/stream/*- Proxies streaming requests to httpbin.org with chunked encoding
Run the test suite:
# Run all tests
go test ./...
# Run tests with verbose output
go test -v ./...
# Run tests for a specific package
go test ./internal/request
go test ./internal/headersThe project is organized into several internal packages:
- request - HTTP request parsing
- response - HTTP response writing
- headers - Header parsing and manipulation
- server - TCP server and connection handling
- Make your changes to the codebase
- Run tests to ensure nothing breaks
- Test manually with curl or your browser
Press Ctrl+C to gracefully stop the server.
curl -X POST http://localhost:42069/ \
-H "Content-Type: application/json" \
-d '{"type": "dark mode", "size": "medium"}'curl -i http://localhost:42069/curl http://localhost:42069/httpbin/stream/10 -vThis will show chunked response with SHA256 hash and content length in trailers.
MIT License - see LICENSE file for details