Project_ZeroPy_Net_Engine

Zero-Dependency HTTP Server

Project Idea & Concept Overview

This project is a zero-dependency HTTP/1.1 static file server written in Python using only the standard library. It listens on a raw TCP socket, accepts concurrent client connections, parses raw HTTP request bytes, and serves files from a local directory without any third-party packages.

The server is intentionally small but realistic: it supports standard GET and HEAD requests, serves static files and directory indexes, and responds cleanly to browsers and command-line clients such as curl and nc.

Expected Behavior

Protocol Boundaries

This project intentionally targets a pragmatic subset of HTTP/1.1:


Architecture Blueprint

Module Boundaries

TCP Socket Lifecycle

  1. The server creates a listening IPv4 TCP socket with socket.AF_INET and socket.SOCK_STREAM
  2. It binds to the configured host and port and begins accepting connections
  3. For each connection, a new thread is spawned to isolate request processing
  4. Data is read in chunks from the socket and accumulated in a bytearray
  5. Once the request is complete, it is parsed into method, path, headers, and body
  6. A route handler resolves the file path within the document root and writes an HTTP response
  7. The socket is closed after the response is sent, which keeps the implementation simple and reliable

Raw Byte Stream Processing Flow

Socket Read -> Byte Buffer Parsing -> Handler Dispatch -> Raw Response Framing

Detailed flow:

  1. recv() fills a buffer with raw bytes from the client socket
  2. The code waits for the HTTP header terminator (\r\n\r\n)
  3. If a Content-Length header is present, the parser continues reading until the full body is available
  4. The complete request is converted from raw bytes into a structured Request
  5. File resolution and method validation occur in the dispatcher
  6. A Response object is converted to bytes using the HTTP status line, headers, and body framing
  7. sendall() transmits the response back to the client

Project File Structure

Zero_dep_hack/
├── README.md
├── STDLIB.md
├── server.py
└── public/
    └── index.html

No requirements.txt or package manifest is included because the project is intentionally zero-dependency.


Complete Implementation Code

The runnable implementation is in server.py. It includes:


Testing & Verification Guide

1. Run the server

cd /path/to/Zero_dep_hack
python3 server.py --host 127.0.0.1 --port 8080 --directory public

2. Test with curl

curl -i http://127.0.0.1:8080/

Expected outcome:

3. Test HEAD request

curl -I http://127.0.0.1:8080/

4. Test a missing page

curl -i http://127.0.0.1:8080/does-not-exist.html

Expected outcome: 404 Not Found

5. Test with netcat

nc 127.0.0.1 8080
GET / HTTP/1.1
Host: localhost

The server will respond with a valid HTTP/1.1 message.

6. Stop the server

Press Ctrl+C in the terminal running the Python process.


Notes

This implementation is designed to be idiomatic, robust, and clearly aligned with the Track C requirements: no third-party dependencies, explicit concurrency, direct socket handling, and clean CLI execution.