How sohailraoufi/httpy works
Main Components
• Server Entry Point & CLI: Although the README instructs to run the server using “python httpy.py”, the key functionality is likely in the src/http.py file. This module acts as the main entry point, parsing command-line arguments (host, port, path, --log) and initializing the server.
• HTTP Listener & Connection Manager: Within http.py (or along with other modules), a core socket listener waits for incoming HTTP requests.
• Request Parsing Module: Look for logic in http.py (or helper modules like another.py if it contains extra features) that parses incoming HTTP requests. This module translates raw socket data into structured requests.
• File Serving & Directory Listing Module: Core logic to serve static files and generate HTML listings for directories. This component reads files from the specified directory (passed via --path) and produces the appropriate HTTP response.
• Logging Component: If the --log flag is enabled, a subcomponent handles different log levels and outputs status and error logs.
• Optional/Helper Modules: The files such as src/another.py and src/name.py might offer supplementary functionalities – for example, supporting utility functions or additional request handling logic.
Analyzing Component Interactions
• Command-Line Interface → Server Initialization: The process begins when the server is started with certain arguments (host, port, path, etc.). This affects configuration and bootstraps other modules.
• Client (Web Browser) → Socket Listener: Incoming HTTP requests from clients are accepted on a specified host and port.
• Socket Listener → Request Parser & Routing: After receiving requests, the listener passes data to the request parser for analysis.
• Request Parser → File Serving Module: Parsed requests are then sent to the file serving component which either locates the file or generates an HTML directory listing.
• File Serving Module → Response Generator: This component crafts HTTP responses (headers + content) and sends them back via the same connection to the client.
• Optionally, Logging occurs at each major step (when enabled).
Architectural Patterns and Design Principles
• Modular Design: The project is broken down into clear, separate modules (possibly the ones in “src/”) to handle different responsibilities (server initialization, request handling, file serving).
• Single Responsibility: Each module or file has a specific purpose (e.g., one file for HTTP functions, another for additional utilities).
• Command-Line Driven Configuration: The design supports runtime configuration using command-line arguments, ensuring flexibility.
• Minimal Dependencies: With a focus on pure Python socket implementation, the design emphasizes simplicity and direct control over HTTP transactions.