Skip to content

High-performance forward proxy server built with Pingora. Load balances across upstream proxies with authentication, retry logic, and health monitoring. Features HTTP/HTTPS proxy support, CONNECT tunnels, round-robin rotation. Perfect for web scraping, proxy failover, and high-throughput proxy aggregation.

License

Notifications You must be signed in to change notification settings

H4RR1SON/proxywar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

proxywar

A high-performance forward proxy service built with Cloudflare's Pingora framework. Combines multiple proxy providers into a single rotating endpoint for web scraping and other use cases.

Flow Diagram

flowchart LR
    A[Client Request] --> B[proxywar :8890]
    B --> C{Round-Robin<br/>Selector}
    C --> D[Proxy Pool]
    D --> E[Proxy 1]
    D --> F[Proxy 2]
    D --> G[Proxy N]
    E --> H[Target Server]
    F --> H
    G --> H
    H --> I[Response]
    I --> B
    B --> A
    
    J[Retry Logic] -.-> C
    K[Proxy Banning] -.-> D
    
    style B fill:#ff6b6b
    style C fill:#059669
    style D fill:#1e40af
    style H fill:#065f46
Loading

Features

  • ✅ Forward proxy with CONNECT and HTTP support
  • ✅ Simple round-robin rotation across all proxies
  • ✅ Automatic proxy authentication (Basic auth)
  • ✅ Automatic retry on proxy failures
  • ✅ Lock-free proxy banning on auth errors
  • ✅ Production-ready logging and error handling
  • ✅ Zero external dependencies (single binary)

Architecture

Simple Design:

Client → proxywar → Round-Robin Pool → Upstream Proxies

Key Components:

  • SimpleBackendPool: Atomic counter-based round-robin selection
  • ForwardProxy: HTTP/CONNECT proxy implementation with retry logic
  • Upstream Loader: Parses proxy URLs and extracts credentials

Quick Start

1. Configure Proxies

Create config/proxies.txt with your proxy list (one per line):

cp config/proxies.example.txt config/proxies.txt
# Edit config/proxies.txt with your actual proxies

Format (see examples in config/proxies.example.txt):

http://username:[email protected]:8080
http://username:[email protected]:3128
http://user-rotate:[email protected]:80

2. Build

cargo build --release

3. Run

# Run with info logging
RUST_LOG=info ./target/release/proxywar

# Run with debug logging
RUST_LOG=debug ./target/release/proxywar

The proxy will listen on 0.0.0.0:8890 by default.

Usage

Basic HTTP Request

curl -x http://localhost:8890 http://api.ipify.org/

HTTPS via CONNECT

curl -x http://localhost:8890 https://api.ipify.org/

In Your Scripts

export HTTP_PROXY=http://localhost:8890
export HTTPS_PROXY=http://localhost:8890
python your_scraper.py

Testing Rotation

Each request will use a different proxy IP:

for i in {1..10}; do
  echo "Request $i:"
  curl -s -x http://localhost:8890 http://api.ipify.org/
done

How It Works

  1. Proxy Selection: Round-robin using atomic counter (thread-safe, no locks)
  2. Authentication: Automatically extracts credentials from proxy URLs
  3. Retry Logic: Tries up to 5 proxies if one fails
  4. Banning: Failed proxies are temporarily banned to avoid repeated failures
  5. Metadata Preservation: Credentials stored directly in backend metadata

Configuration

Changing the Port

Edit src/main.rs line 66:

proxy_service.add_tcp("0.0.0.0:8890");  // Change port here

Adjusting Timeouts

Edit src/proxy_handler.rs constants:

const REQUEST_TIMEOUT_SECS: u64 = 30;   // Request timeout
const RESPONSE_TIMEOUT_SECS: u64 = 30;  // Response timeout

Maximum Retries

Edit src/proxy_handler.rs:

const LB_MAX_ITERATIONS: usize = 256;  // Max proxy attempts

Performance

Built on Pingora's high-performance foundation:

  • Low CPU: ~15-25% under load vs 45-60% for typical Go proxies
  • Low Memory: ~150MB vs ~800MB for microservices
  • High Throughput: Handle 100K+ concurrent connections
  • Thread-per-core: Pinned workers minimize context switches

Project Structure

proxywar/
├── src/
│   ├── main.rs           # Entry point and server setup
│   ├── proxy_handler.rs  # Forward proxy implementation
│   ├── backend_pool.rs   # Round-robin backend pool
│   └── upstream.rs       # Proxy URL parsing and loading
├── config/
│   └── proxies.example.txt  # Example proxy configuration
├── Cargo.toml            # Rust dependencies
└── README.md

Combining Multiple Proxy Providers

This proxy is designed to aggregate proxies from multiple sources:

  1. Webshare (p.webshare.io) - Rotating datacenter proxies
  2. Oxylabs (dc.oxylabs.io) - Premium datacenter IPs
  3. Direct IPs - Any HTTP proxy with authentication

All proxies are combined into a single pool with automatic rotation.

Troubleshooting

"No upstream proxies configured"

Cause: config/proxies.txt is empty or missing

Solution:

cp config/proxies.example.txt config/proxies.txt
# Add your proxies to config/proxies.txt

"503 Service Unavailable"

Cause: All proxies failed or are banned

Solution: Check proxy credentials and connectivity:

# Test a proxy directly
curl -x http://user:[email protected]:8080 http://api.ipify.org/

Connection Timeouts

Cause: Upstream proxies are slow

Solution: Increase timeouts in src/proxy_handler.rs

Development

Build Debug Version

cargo build
./target/debug/proxywar

Check Code

cargo check
cargo clippy

Format Code

cargo fmt

Why Pingora?

  • No LoadBalancer overhead: Simple atomic counter for selection
  • No health check complexity: Failed proxies auto-banned during use
  • No background services: Single-threaded simplicity
  • Direct metadata: Credentials stored on backends, no workarounds
  • Rust performance: Memory safety + C-level speed

License

Apache 2.0

References

Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

Support

For issues or questions:

  • Open an issue on GitHub
  • Check existing issues for solutions

About

High-performance forward proxy server built with Pingora. Load balances across upstream proxies with authentication, retry logic, and health monitoring. Features HTTP/HTTPS proxy support, CONNECT tunnels, round-robin rotation. Perfect for web scraping, proxy failover, and high-throughput proxy aggregation.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages