A high-performance, thread-safe HTTP/1.1 server in pure C that supports concurrent GET and PUT requests. Designed for speed, safety, and correctness, this server uses a synchronized work queue, thread pool, and fine-grained file-level locking.
- 🧵 Multithreaded: Thread pool for concurrent request handling
- 🧺 Synchronized Work Queue: Producer-consumer model using mutex and semaphores
- 🔐 File-Level Concurrency: Read-write locks ensure safe GET/PUT access
- 📄 HTTP/1.1 Support: Parses headers, body,
Content-Length,Request-Id - 🛠️ Robust Error Handling: Handles malformed input, system errors, EINTR
- 🪵 Thread-Safe Logging: Logs all requests with status codes and IDs
- 🧼 Graceful Shutdown: Signal handlers for SIGINT/SIGTERM cleanup
.
├── httpserver.c # Main server source code
├── Makefile # For building the server
├── README.md # This file
├── test_repo.sh # Sample test script
├── load_repo.sh # Optional script to load test files
├── config.json # Sample config (optional)
├── output.txt # Sample output (optional)
├── error.txt # Sample error log (optional)
└── workloads/ # Test files directory (optional)
makeOr compile manually:
gcc -pthread -o httpserver httpserver.c./httpserver -t <num_threads> <port>Example:
./httpserver -t 4 8080PUT Request
curl -X PUT -H "Request-Id: 123" --data "hello world" http://localhost:8080/hello.txtGET Request
curl -X GET -H "Request-Id: 456" http://localhost:8080/hello.txtRun all your test cases:
./test_repo.shThe server handles Ctrl+C or SIGTERM, cleans up threads and locks, and shuts down cleanly.
- Thread pools and pthreads
- Producer-consumer queue using mutex/semaphore
- Per-file fine-grained locking (readers-writer locks)
- HTTP/1.1 protocol parsing and validation
- Memory safety and resource cleanup
- Signal handling in concurrent systems