Skip to content

b00rg/proxy-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multithreaded HTTP/HTTPS Proxy Server

A Python-based multithreaded proxy server that supports both HTTP and HTTPS traffic, implements caching, domain blocking, and provides a management console for runtime control and statistics.

The proxy listens locally and forwards browser traffic to destination servers while optionally caching responses and filtering requests.


Features

1. HTTP and HTTPS Support

  • Handles standard HTTP requests (GET, POST, etc.).
  • Supports HTTPS tunneling using the CONNECT method.
  • HTTPS traffic is securely forwarded between client and server.

2. Multithreaded Architecture

  • Uses a thread pool to handle multiple clients concurrently.
  • Default pool size: 20 worker threads.

3. Response Caching

The proxy caches HTTP responses to improve performance.

Cache properties:

Property Value
TTL 60 seconds
Max cache entries 50
Max object size 1 MB

Cached responses are served instantly when valid.

4. Domain Blocking

A blocklist allows preventing access to specific hosts.

Example blocked response:

HTTP/1.1 403 Forbidden
Blocked by proxy.

5. Management Console

A built-in console allows live proxy control while the server is running.

Supported commands:

Command Description
block <host> Block a domain
unblock <host> Remove domain from blocklist
show blocklist Display blocked domains
show cache List cached responses
clear cache Clear all cached entries
stats Show cache hit/miss statistics
help Show all commands

6. Performance Logging

All HTTP requests are logged to:

timing_log.txt

Each entry records:

timestamp, HIT/MISS, response_time, url

Statistics can be viewed via the stats command.

Example metrics:

  • Cache hit rate
  • Average response time
  • Speedup from caching

Architecture Overview

The proxy consists of the following components:

Client Browser
      │
      ▼
 TCPServer
      │
      ▼
Request_Parser
      │
 ┌───────────────┐
 ▼               ▼
Http_Handler   Https_Handler
 │               │
 ▼               ▼
Cache         Tunnel traffic
 │
 ▼
Origin Server

Core Classes

Class Responsibility
TCPServer Accepts client connections and distributes them to worker threads
Request_Parser Extracts method, host, port, and path from client requests
Http_Handler Processes HTTP requests and manages caching
Https_Handler Creates encrypted tunnels for HTTPS traffic
Management_Console Provides runtime proxy management

Installation

Requirements:

Python 3.8+

Clone the repository:

git clone https://github.com/yourusername/proxy-server
cd proxy-server

Running the Proxy

Start the proxy server:

python proxy.py

Expected output:

[PROXY] Listening on 127.0.0.1:8888
[PROXY] Set your browser proxy to 127.0.0.1:8888
[CONSOLE] Management console ready. Type 'help' for commands.

Configure Your Browser

Set your browser proxy settings to:

Host: 127.0.0.1
Port: 8888

Example locations:

Chrome / Edge

Settings → System → Open Proxy Settings

Firefox

Settings → Network Settings → Manual Proxy Configuration

Example Proxy Output

[12:03:44] 127.0.0.1 — GET example.com/index.html
[CACHE MISS] example.com/index.html — fetched in 0.2443s (12438 bytes)

[12:03:50] 127.0.0.1 — GET example.com/index.html
[CACHE HIT ] example.com/index.html — served in 0.0002s (age 6s)

Cache Statistics Example

── Cache Statistics ──────────────────────
Total requests  : 20
Cache hits      : 12  (60%)
Cache misses    : 8   (40%)
Avg HIT time    : 0.0003s
Avg MISS time   : 0.2011s
Cache is 670x faster than origin
──────────────────────────────────────────

About

A web proxy server in python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages