How shatanshu3006/server-from-scratch works
Project Type and Purpose
• Type: Standalone, full-fledged HTTP server (no external frameworks).
• Purpose:
• Listen for TCP connections on a configurable port
• Parse raw HTTP/1.x requests
• Serve static files from WebRoot/
• Handle basic MIME detection, errors, and JSON-based configuration
• Support multi-threaded request handling
Core Components (from File Tree & README)
• Entry Point & Utilities (com.util):
• HttpServer.java – main() method; bootstraps listener
• Json.java – JSON helper for config
• Configuration (com.httpserver.config):
• ConfigurationManager – loads/parses http.json
• Configuration – holds port, threadPoolSize, webRoot path…
• Server Engine (com.httpserver.core):
• ServerListenerThread – accepts new sockets, hands off to worker threads
• HttpConnectionWorkerThread – reads from socket, invokes parser & handler
• I/O & Routing (com.httpserver.core.io):
• WebRootHandler – locates static file in WebRoot/, streams bytes back
• Exceptions: WebRootNotFoundException, ReadFileException
• HTTP Protocol (com.http):
• HttpParser – scannerless parsing of request-line + headers
• Domain classes: HttpRequest, HttpMessage, enums for HttpMethod, HttpVersion, HttpStatusCode
• Exceptions: HttpParsingException, BadHttpVersionException
Additional Insights from README
• Multi-threaded design: one listener thread + multiple worker threads
• JSON config schema in resource/http.json
• JUnit 5 tests for parser, version, headers, WebRootHandler