| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A minimal WSGI HTTP server built from scratch in Python.
This project demonstrates:
custom-server/
│
├── src/
│ ├── server.py # Core prefork server
│ ├── request.py # HTTP request parser
│ ├── response.py # HTTP response builder
│ ├── wsgi.py # WSGI bridge
│ ├── cli.py # Logging & CLI utilities
│ └── config.py # Central configuration
│
├── examples/
│ └── flask_app.py # Example Flask app
│
├── main.py # CLI entry point
├── requirements.txt
└── README.mdgit clone git@github.com:kkamal11/custom-python-http-server.git
cd root_directorypython -m venv venv
source venv/bin/activate pip install -r requirements.txtpython3 main.py --helpTo run with Default Settings:
python main.py examples.flask_app:appTo run with custom host and port:
python main.py examples.flask_app:app --host 127.0.0.1 --port 8080To run with multiple workers:
python main.py examples.flask_app:app --workers 4To run with a custom WSGI app:
python main.py module:callable_app# examples/flask_app.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Hello from Custom HTTP Server app!"from django.conf import settings
from django.core.wsgi import get_wsgi_application
from django.http import HttpResponse
from django.urls import path
settings.configure(
DEBUG=True,
SECRET_KEY="super-secret-key-1234567890$@qwertyuiop",
ROOT_URLCONF=__name__,
ALLOWED_HOSTS=["*"],
MIDDLEWARE=[],
)
def home(request):
return HttpResponse("Hello from Django via Custom HTTP Server!")
urlpatterns = [
path("", home),
]
app = get_wsgi_application()Logs are printed to the console in Common Log Format:
[12:44:12] 127.0.0.1 "GET / HTTP/1.1" 200 42 0.75msIt uses a prefork worker model:
Master Process
├── Worker 1
├── Worker 2
├── Worker 3
└── Worker NMaster process listens for incoming connections and dispatches them to worker processes. Each worker handles requests independently, allowing for concurrent processing.
The server can be gracefully shut down using Ctrl+C. The master process will signal all worker processes to terminate, allowing them to finish processing any ongoing requests before exiting.
Usage:
python main.py module:app [OPTIONS]
Options:
--host Bind host (default: 127.0.0.1)
--port Bind port (default: 8000)
--workers Number of worker processes (default: 1)
--help Show help messageThis is a minimal implementation for educational purposes. It lacks many features of a production server like Gunicorn, such as:
I made it it as a learning tool and a starting point for building a more robust server and get to know how does a production WSGI server work!
Kamal Kishor – GitHub
| Back | FazBrowse Home | New Git URL |