No project description provided
Project description
HTTP Proxy CLI
A lightweight HTTP proxy CLI tool that intercepts and logs all requests to/from a specific target site.
Features
- ✅ Command-line interface with rich argument support
- ✅ Intercepts all HTTP methods (GET, POST, PUT, DELETE, etc.)
- ✅ Complete logging of requests and responses
- ✅ Configurable output formats (JSON or plain text)
- ✅ Flexible logging levels and file locations
- ✅ Real-time statistics and testing tools
Quick Start
Installation
Option 1: Install as package (recommended)
cd agent-proxy
pip install -e .
# Now you can import as:
# from agent_proxy.proxy import SimpleProxy
# from agent_proxy.logger import ProxyLogger
Option 2: Install dependencies only
cd agent-proxy
pip install -r requirements.txt
# You can run the CLI as a module, but imports must use the agent_proxy prefix.
Note: CLI scripts (http-proxy, proxy-stats, proxy-test) are available when installing the package (pip install -e .) or when running via Poetry (poetry run ...).
Using Poetry (alternative):
cd agent-proxy
poetry install
# run CLI via Poetry
poetry run http-proxy --help
# import in Python as:
# from agent_proxy.proxy import SimpleProxy
# from agent_proxy.logger import ProxyLogger
CLI Usage
Basic usage:
# Start proxy with default settings
http-proxy --target https://api.example.com
# Custom port and host
http-proxy --target https://httpbin.org --port 8080 --host 0.0.0.0
# Custom logging
http-proxy --target https://jsonplaceholder.typicode.com \
--log-file my_logs.json \
--log-level DEBUG \
--log-format json
CLI Commands
Main proxy command:
http-proxy --target https://api.example.com [OPTIONS]
Show statistics:
proxy-stats --log-file proxy_requests.log
Test target connectivity:
proxy-test --target https://api.example.com --path /health
CLI Arguments
| Argument | Short | Default | Description |
|---|---|---|---|
--target |
-t |
required | Target URL to proxy requests to |
--host |
-h |
127.0.0.1 |
Host to bind the proxy server to |
--port |
-p |
8000 |
Port to bind the proxy server to |
--log-file |
-l |
logs/proxy_requests.log |
Log file path (default folder: logs/) |
--log-level |
-v |
INFO |
Logging level (DEBUG, INFO, WARNING, ERROR) |
--log-format |
-f |
json |
Log format (json or plain) |
--no-console |
False |
Disable console logging output | |
--reload |
False |
Enable auto-reload for development | |
--workers |
-w |
1 |
Number of worker processes |
Examples
Basic proxy setup:
# Proxy to httpbin.org on port 8080
http-proxy --target https://httpbin.org --port 8080
# Test with curl
curl http://localhost:8080/get
curl -X POST http://localhost:8080/post -d '{"test": "data"}'
Advanced logging:
# Debug mode with plain text logs
http-proxy --target https://api.github.com \
--log-level DEBUG \
--log-format plain \
--log-file github_logs.txt
# Quiet mode (no console output)
http-proxy --target https://api.example.com --no-console
Production setup:
# Bind to all interfaces with multiple workers
http-proxy --target https://api.example.com \
--host 0.0.0.0 \
--port 80 \
--workers 4 \
--log-level WARNING
Testing and Statistics
Check proxy statistics:
# Show basic stats
proxy-stats
# Custom log file
proxy-stats --log-file custom_logs.json
Test target connectivity:
# Basic connectivity test
proxy-test --target https://api.example.com
# Test specific endpoint
proxy-test --target https://api.example.com --path /health
Log Format
JSON format (default):
{
"type": "request",
"request_id": "req_1234567890",
"timestamp": "2024-01-15T10:30:00.123456",
"method": "POST",
"url": "https://api.example.com/users",
"headers": {
"content-type": "application/json",
"authorization": "Bearer token123"
},
"body": "{\"name\": \"John\", \"email\": \"john@example.com\"}",
"size": 45
}
Plain text format:
2024-01-15 10:30:00 - INFO - REQUEST [req_1234567890] POST https://api.example.com/users - Headers: 5 - Body: 45 bytes
Python Module Usage
Direct usage:
from agent_proxy.proxy import SimpleProxy
from agent_proxy.logger import ProxyLogger
# Create custom logger
logger = ProxyLogger(log_file="custom.log", log_format="json")
# Create proxy
proxy = SimpleProxy("https://api.example.com", logger)
app = proxy.create_app()
# Run with uvicorn
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
Development
Install in development mode:
pip install -e .
Run tests:
# Using CLI scripts (after install):
http-proxy --help
proxy-stats --help
proxy-test --help
# Or as a module (if not installed):
python -m agent_proxy.cli --help
python -m agent_proxy.cli --target https://httpbin.org --port 8080
Package structure
Your package now uses the following structure for importable modules:
src/
agent_proxy/
__init__.py
cli.py
logger.py
proxy.py
Log Files
proxy_requests.log: Detailed request/response logs- Console output: Real-time request tracking
Error Handling
The CLI handles common errors gracefully:
- Invalid URLs: Validates target URLs start with http:// or https://
- Connection errors: Returns appropriate HTTP status codes
- Timeout handling: 30s default timeout with proper error responses
- Port conflicts: Clear error messages for port binding issues
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agent_proxy-0.2.4.tar.gz.
File metadata
- Download URL: agent_proxy-0.2.4.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.13.5 Darwin/24.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5243492b357ad848a17d5e1d93fe4e59937514752b74f3b0e97a6efdfabb3602
|
|
| MD5 |
93ae414f2679203f93cb728701d23092
|
|
| BLAKE2b-256 |
88f6a4da09e20dd3c3bfa78d59045668712e96abf905750090ecabfc4bea5995
|
File details
Details for the file agent_proxy-0.2.4-py3-none-any.whl.
File metadata
- Download URL: agent_proxy-0.2.4-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.13.5 Darwin/24.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f32d67b4f2434851326031042d47541a0775e5f41ef0f6e99dbe60895132b6b6
|
|
| MD5 |
e34398225024431b6bac0ab978e1d86f
|
|
| BLAKE2b-256 |
7bde12a432e932be611e6b862d09c1b34bb9b109c17b7dfa32bda541e506c6d8
|