A lightweight, RFC-compliant HTTP/1.1 server built from scratch in Java. Designed as a standalone logging service that external applications can use to persist log entries remotely.
| Feature | Description |
|---|---|
| Hand-rolled HTTP Parser | Byte-by-byte parsing of request-line, headers, and body following HTTP/1.1 spec |
| Virtual Threads | Leverages Java 21 virtual threads for efficient concurrent connection handling |
| Streaming Body Reader | Memory-efficient 8-byte chunked body reading with consumer callbacks |
| JSON Configuration | Fully configurable via server.json — ports, timeouts, allowed methods/headers |
| Custom Exception | Typed HTTP exceptions mapped directly to proper status codes |
| File-based Logging Endpoint | POST log entries organized by application name and log file |
- Java 21 — Virtual threads, records, pattern matching
- Maven — Build tooling
- Jackson — JSON configuration parsing
- SLF4J + Log4j2 — Structured logging
- JUnit 5 — Testing framework
The parser is the core of this project — a byte-level state machine that strictly follows HTTP/1.1 semantics.
GET /api/logs HTTP/1.1\r\n
│ │ │
│ │ └─► Version validation (only HTTP/1.1 supported)
│ └───────────► Request target extraction with length limits
└───────────────► Method validation against configured allowlist
Key Features:
- Configurable method allowlist — Only parses methods you explicitly support
- CRLF enforcement — Strictly validates
\r\nsequences per spec
// Lazy streaming — body isn't read until handler requests it
request.getBodyReader().ifPresent(reader ->
reader.readTo(chunk -> processChunk(chunk))
);File Organization:
server_logs/
├── my-app/
│ ├── errors.txt ← Log-At: errors
│ └── access.txt ← Log-At: access
└── other-app/
└── debug.txt
- Java 21+
- Maven 3.6+
# Clone and build
mvn clean compile
# Start server
mvn exec:java -Dexec.mainClass="org.http_servers.HttpServer"
# Server starts on http://localhost:8080# Health check
curl http://localhost:8080/
# Post a log entry
curl -X POST http://localhost:8080/ \
-H "Application: test-app" \
-H "Log-At: events" \
-H "Content-Type: text/plain" \
-H "Content-Length: 11" \
-d "Hello World"Made to understand HTTP
