A mini HTTP proxy server written in Go that listens on a local port and forwards HTTP requests to real servers. It logs headers, URLs, and response times for all requests.
- Listens on TCP socket (port 8080 by default)
- Forwards HTTP requests from clients to target servers
- Logs request headers, URLs, and response times
- Client <-> Proxy <-> Server architecture
- Handles HTTP request/response using TCP sockets
go build -o bin/proxy main.go./bin/proxyThe proxy server will start listening on port 8080.
Open a new terminal and run:
# Test with a simple HTTP request
curl -x http://localhost:8080 http://httpbin.org/get
# Test with headers
curl -x http://localhost:8080 -H "User-Agent: Test-Proxy" http://httpbin.org/headers
# Test POST request
curl -x http://localhost:8080 -X POST -d "test=data" http://httpbin.org/postwget -e http_proxy=http://localhost:8080 http://httpbin.org/get- Open your browser settings
- Configure HTTP proxy to:
localhost:8080 - Visit any HTTP website
- Check the proxy server logs for request details
export http_proxy=http://localhost:8080
curl http://httpbin.org/getThe proxy server logs the following information for each request:
- Timestamp: When the request was received
- Method: HTTP method (GET, POST, etc.)
- URL: Full URL of the request
- Headers: All request headers
- Status Code: HTTP response status code
- Response Time: Time taken to get response from server
- Response Headers: All response headers
2024/01/15 10:30:45 HTTP Proxy Server listening on port 8080
2024/01/15 10:30:45 Ready to accept connections...
2024/01/15 10:31:12
=== Incoming Request ===
2024/01/15 10:31:12 Time: 2024-01-15 10:31:12
2024/01/15 10:31:12 Method: GET
2024/01/15 10:31:12 URL: http://httpbin.org/get
2024/01/15 10:31:12 Headers:
2024/01/15 10:31:12 User-Agent: curl/7.68.0
2024/01/15 10:31:12 Accept: */*
2024/01/15 10:31:12
=== Response ===
2024/01/15 10:31:12 Status Code: 200
2024/01/15 10:31:12 Response Time: 245ms
2024/01/15 10:31:12 Response Headers:
2024/01/15 10:31:12 Content-Type: application/json
2024/01/15 10:31:12 Content-Length: 123
2024/01/15 10:31:12 ===================
proxy/
├── main.go # Main proxy server implementation
├── go.mod # Go module file
├── README.md # This file
└── bin/ # Build output directory (created after build)
- Go 1.21 or higher
- Start the proxy server in one terminal
- Make test requests using curl in another terminal
- Show the logs displaying headers, URLs, and response times
- Explain the architecture: Client sends request to proxy, proxy forwards to server, server responds through proxy back to client
- Demonstrate TCP socket usage by showing network connections
- Show HTTP request/response handling through the logs