TCP-based HTTP server with two modes:
- Simple server
- HTTP proxy with filtering and blocking
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
- Parse arguments:
config_path,--proxy,--ip,--port,--buffsize - Load JSON config (if provided):
blockedforbidden_words
- Start TCP server (
bind,listen) - Accept client connections
- Receive full HTTP request
- Parses request
- Returns fixed
HTTP 200 OK - No external communication
- Validate
Hostheader - Checks request validity depending on .json criteria:
- Block →
403 Forbidden - Invalid →
400 Bad Request
- Block →
- Forward request to destination server
- Receive response (with timeout)
- Send response (modified or not) back to client
python3 tcp_socket_server_v4.py --ip 127.0.0.1 --port 80python3 tcp_socket_server_v4.py <config.json> --proxy --ip 127.0.0.1 --port 80--buffsizedefaults to 50--proxyrequires a config file
{
"blocked": ["example.com"],
"forbidden_words": ["word1", "word2"]
}- 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