A lightweight, educational HTTP server implementation in Go using standard library, designed to demonstrate core web server concepts including request parsing, response handling, and basic routing. Includes additional utilities for TCP listening and UDP messaging.
miniHttp is a minimal HTTP/1.1 server built from scratch in Go, focusing on:
- HTTP request parsing (headers, methods, paths)
- Response generation (status codes, headers, HTML templates)
- Basic routing (static file serving, error pages)
- Concurrent handling (goroutines for client connections)
- Extensibility (modular design with internal packages)
The project also includes companion tools:
- tcplistener: A simple TCP listener for debugging network connections
- udpsender: A UDP message sender for testing network protocols
Built as a learning exercise in low-level networking and HTTP protocol implementation.
- ✅ HTTP/1.1 GET/POST support
- ✅ Custom HTML error pages (200, 400, 500)
- ✅ Header parsing and validation
- ✅ Basic static file serving
- ✅ Concurrent client handling
- ✅ Modular architecture (internal packages)
- ✅ Unit tests for core components
- ✅ CLI tools for network testing
miniHttp/
├── go.mod # Go module definition
├── README.md # This file
├── cmd/ # CLI applications
│ ├── httpServer/ # Main HTTP server
│ │ └── main.go
│ ├── tcplistener/ # TCP listener tool
│ │ └── main.go
│ └── udpsender/ # UDP sender tool
│ └── main.go
├── internal/ # Core business logic
│ ├── headers/ # HTTP header parsing
│ │ ├── headers.go
│ │ └── headers_test.go
│ ├── htmlTemplates/ # HTML response templates
│ │ ├── 200.html
│ │ ├── 400.html
│ │ └── 500.html
│ ├── request/ # HTTP request handling
│ │ ├── request.go
│ │ └── request_test.go
│ ├── response/ # HTTP response generation
│ │ └── response.go
│ └── server/ # Server logic and routing
│ └── server.go
└── test/ # Test data and utilities
└── msgs/
└── messeges.txt # Sample messages for UDP testing
- Go 1.25.4 or later
- Linux/macOS/Windows (tested on Linux)
- No external dependencies (uses only standard library)
# On Arch Linux
sudo pacman -S go
# On Ubuntu/Debian
sudo apt-get install golang-go
# Or download from https://golang.org/dl/git clone https://github.com/itsiros/miniHttp.git
cd miniHttp
# Build all commands
go build ./cmd/httpServer
go build ./cmd/tcplistener
go build ./cmd/udpsender
# Or build everything at once
go build ./...# Run all tests
go test ./...
# Run with verbose output
go test -v ./internal/...Starts a basic HTTP server on port 42069.
# Run the server
./httpServer
# Or directly with go run
go run ./cmd/httpServer/main.goServer behavior:
- Listens on
localhost:42069 - Serves static HTML pages for common status codes
- Handles GET/POST requests
- Returns 200 OK for valid requests
- Returns 400 Bad Request for malformed requests
- Returns 500 Internal Server Error for server issues
Test the server:
# In another terminal
curl http://localhost:42069/
# Returns 200.html content
curl -X POST http://localhost:42069/
# Returns 200.html content
curl http://localhost:42069/invalid
# Returns 400.html contentCustomization:
- Edit
internal/htmlTemplates/*.htmlto change response pages - Modify
internal/server/server.goto add routing logic
A simple TCP server that listens for connections and echoes received data.
# Run on default port 8081
./tcplistener
# Or specify port
./tcplistener -port 9999Usage example:
# Terminal 1: Start listener
./tcplistener
# Terminal 2: Connect and send data
echo "Hello TCP" | nc localhost 8081
# Listener will print received dataSends UDP messages to a specified address.
# Send default message to localhost:8082
./udpsender
# Send custom message
./udpsender -message "Custom UDP message"
# Send to different address
./udpsender -addr "192.168.1.100:9999" -message "Hello remote"Usage example:
# Send message
./udpsender -message "Test message"
# Use with netcat UDP listener
nc -u -l 8082 # Listen for UDP on port 8082
# Then run udpsender in another terminal- Parses HTTP headers from raw request strings
- Validates header format and content
- Unit tests ensure parsing correctness
- Handles incoming HTTP requests
- Extracts method, path, headers, and body
- Validates request format
- Generates HTTP responses
- Sets appropriate status codes and headers
- Uses HTML templates for content
- Main server loop with goroutine-based concurrency
- Routes requests to appropriate handlers
- Manages client connections
- Static HTML files for different HTTP status codes
- Served as response bodies
- Modular architecture: Separated concerns into internal packages
- Dependency injection: Server components are composable
- Error handling: Custom error types and recovery
- Testing: Unit tests for critical parsing logic
# Run header parsing tests
go test ./internal/headers/
# Run request handling tests
go test ./internal/request/
### Network Testing
```bash
# Test TCP listener
echo "test" | nc localhost 8081
# Test UDP sender
./udpsender -message "UDP test"- Follow Go conventions (
gofmt,go vet) - Use meaningful variable names
- Add comments for complex logic
- Keep functions small and focused
- Concurrent: Handles multiple clients simultaneously
- Lightweight: Minimal memory footprint
- Fast startup: No heavy initialization
- Scalable: Goroutine-based design
Benchmarks (approximate, on test machine):
- Request handling: ~1000 req/sec
- Memory usage: <10MB for server
- Startup time: <100ms
- HTTP/1.1 only (no HTTP/2)
- Basic routing (no advanced frameworks)
- No SSL/TLS support
- Limited error handling
- Educational focus (not production-ready)
MIT License - see LICENSE file for details.