Backend
HTTP Server
An HTTP/1.1 server built from scratch in Java using non-blocking I/O, custom request parsing, routing, file uploads, CGI execution, and virtual hosting.
- Java
- Java NIO
- HTTP/1.1
Overview
HTTP Server is a custom HTTP/1.1 web server implemented entirely in Java without external frameworks or server libraries.
The server is built around Java NIO and a single-threaded event loop capable of handling multiple concurrent connections without using a thread-per-client model.
Core HTTP functionality including request parsing, response generation, routing, file serving, uploads, sessions, cookies, virtual hosts, and CGI execution was implemented manually to explore how web servers operate at the protocol and socket level.
The project also includes a custom JSON-based configuration system for managing servers, ports, routes, body limits, redirects, error pages, directory behavior, and CGI handlers.
Problem Statement
Most modern Java applications rely on frameworks that abstract away HTTP communication, connection management, routing, and request parsing.
This project removes those abstractions by implementing the server directly on top of sockets and Java NIO.
The main challenge was to correctly process HTTP/1.1 traffic while keeping the server responsive under concurrent connections, handling partial network data, large request bodies, long-running operations, malformed requests, and persistent connections without blocking the main event loop.
Features Implemented
-
Built an HTTP/1.1 server from scratch using only Java standard libraries.
-
Implemented a single-threaded, event-driven architecture using Java NIO selectors.
-
Added support for multiple listening ports and multiple virtual servers.
-
Implemented name-based virtual hosting using the HTTP
Hostheader. -
Built an incremental HTTP request parser capable of handling partial socket reads.
-
Implemented
GET,POST, andDELETErequest handling. -
Added persistent HTTP connections using HTTP/1.1 keep-alive.
-
Implemented chunked transfer encoding for HTTP request and response bodies.
-
Added configurable request body limits and inactivity timeouts.
-
Streamed large request bodies directly to disk to avoid excessive memory usage.
-
Implemented static file serving with MIME type detection and browser caching headers.
-
Added multipart/form-data and raw binary file uploads.
-
Implemented HTTP redirects and custom error pages.
-
Built server-side session management with cookie support.
-
Implemented CGI execution using Java
ProcessBuilder. -
Added non-blocking CGI process monitoring with execution and output limits.
-
Built a custom JSON parser to load server configuration without external dependencies.
-
Added startup configuration validation for invalid routes, values, and duplicate definitions.
-
Implemented zero-copy static file transfer using
FileChannel.transferTo(). -
Performed concurrent load testing using Siege.
Technical Highlights
-
Built the HTTP/1.1 protocol layer manually without Netty, Jetty, Spring, or other server frameworks.
-
Used Java NIO selectors to implement a single-threaded non-blocking event loop.
-
Designed an incremental parser for partial, chunked, and large HTTP requests.
-
Implemented zero-copy file transfer and disk streaming to reduce memory overhead.
-
Integrated CGI execution without blocking the main network event loop.
-
Built routing, virtual hosting, sessions, configuration parsing, and request handling as independent server components.
Impact
The project provided a low-level understanding of how HTTP servers manage network connections, parse requests, construct responses, route traffic, and maintain state.
Building the server without frameworks required solving concurrency, memory management, file I/O, protocol parsing, security, and process-management concerns directly.
The resulting architecture can handle many concurrent connections through a single event loop while keeping memory usage predictable and avoiding the overhead of assigning a dedicated thread to every client.