This repository contains my Java implementation of a fully functional HTTP/1.1 server, built as part of the Codecrafters "Build Your Own HTTP Server" challenge.
- ✅ HTTP/1.1 protocol parsing (requests and responses)
- ✅ Persistent TCP connections with
Connection: keep-aliveandConnection: close - ✅
/echo/<msg>endpoint (returns plain text or gzip-compressed based on headers) - ✅
/user-agentendpoint (returns client's User-Agent) - ✅
/files/<filename>(supports GET and POST for file retrieval and storage) - ✅ Custom headers, status codes, and MIME types
- ✅ Multithreaded request handling using a thread pool
- Java 11+
- Maven
./your_program.shmvn clean compile exec:java -Dexec.mainClass="Main"curl -v http://localhost:4221/
curl -v http://localhost:4221/user-agent
curl -v http://localhost:4221/echo/hello
curl -v --header "Accept-Encoding: gzip" http://localhost:4221/echo/compressed
curl -X POST --data "This is a file." http://localhost:4221/files/test.txt
curl http://localhost:4221/files/test.txtHTTPServer.java– Core server logic (multi-threaded socket handling, routing)HTTPRequest.java– Request parsing (method, path, headers, body)HTTPResponse.java– Response builder with status, headers, and bodyContentType.java– MIME type handlingMain.java– Entry point
This project was a deep dive into how real web servers work under the hood. It helped me learn:
- Low-level networking with Java
SocketAPIs - HTTP request parsing and protocol rules
- How headers, compression, and status codes work
- Graceful connection handling and concurrency