Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyServer — Pure Python HTTP Server

A multi-threaded HTTP/1.1 web server built from scratch using only the Python standard library (socket, threading) — no Flask, no Django, no http.server.

Features

  • Raw TCP socket listening + HTTP/1.1 request parsing (method, path, query, headers, body)
  • Router with dynamic path segments: /api/notes/<id>
  • JSON API endpoints with automatic 400 on bad input
  • Static file serving from static/ with MIME-type detection and ../ traversal protection
  • Correct status codes: 200 / 201 / 400 / 403 / 404 / 405 (+ Allow header)
  • Thread-per-client concurrency
  • Graceful shutdown via Ctrl+C

Run

python server.py           
python server.py --port 9000

Project Structure

Http_Server/
│
├── server.py                    # Main server implementation
│   ├── TTLCache class           # LRU cache with TTL
│   ├── RateLimiter class        # Token bucket rate limiter
│   ├── HTTPRequest class        # Request parser/representation
│   ├── HTTPResponse class       # Response builder
│   ├── Router class             # URL routing
│   ├── PyServer class           # Main server
│   ├── Routes (decorators)      # API endpoints
│   └── main()                   # Entry point
│
├── benchmark.py                 # Load testing tool
│   ├── raw_request()            # HTTP client
│   ├── worker()                 # Concurrent worker
│   ├── percentile()             # Statistics helper
│   └── main()                   # Entry point
│
├── static/                      # Static file directory
│   ├── index.html               # Default page
│
└── benchmark_20c.json            # Generated benchmark results

API

Endpoint Description
GET /api/hello?name=You Greeting JSON
GET /api/info Server & request info
GET /api/notes List notes
POST /api/notes Create note — body: {"title": "...", "body": "..."}
GET /api/notes/<id> Get one note

Dependencies

Python Standard Library only:

Module Purpose
socket Network communication
threading Concurrency
json API data serialization
os File operations
time Timing and caching
logging Debugging
argparse CLI argument parsing
collections Data structures (OrderedDict, Counter)
urllib URL parsing
mimetypes MIME type detection
statistics Statistical calculations

Architecture

PyServer Architecture

Request Flow

PyServer Architecture

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages