Skip to content

the-alquemist/HTTP-Proxy-101

Repository files navigation

Proxy HTTP Server — CC4303

TCP-based HTTP server with two modes:

  • Simple server
  • HTTP proxy with filtering and blocking

Overview

tcp_socket_server_v4.py:

  • Handles full HTTP requests (including body)
  • Can forward requests to external servers (proxy mode)
  • Applies blocking rules and content filtering

How It Works

General Flow

  1. Parse arguments: config_path, --proxy, --ip, --port, --buffsize
  2. Load JSON config (if provided):
    • blocked
    • forbidden_words
  3. Start TCP server (bind, listen)
  4. Accept client connections
  5. Receive full HTTP request

Modes

Simple Mode (default)

  • Parses request
  • Returns fixed HTTP 200 OK
  • No external communication

Proxy Mode (--proxy)

  1. Validate Host header
  2. Checks request validity depending on .json criteria:
    • Block → 403 Forbidden
    • Invalid → 400 Bad Request
  3. Forward request to destination server
  4. Receive response (with timeout)
  5. Send response (modified or not) back to client

Usage

Simple Mode

python3 tcp_socket_server_v4.py --ip 127.0.0.1 --port 80

Proxy Mode

python3 tcp_socket_server_v4.py <config.json> --proxy --ip 127.0.0.1 --port 80

Notes

  • --buffsize defaults to 50
  • --proxy requires a config file

Config Example

{
  "blocked": ["example.com"],
  "forbidden_words": ["word1", "word2"]
}

Key Design Choices

  • Full HTTP request handling using Content-Length
  • Modular functions (parsing, blocking, filtering)
  • External JSON config (no hardcoding)
  • Response rewriting with correct Content-Length
  • Timeout for upstream server
  • Clean socket handling

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages