Easy HTTP Proxy Server
A simple HTTP/HTTPS proxy server with connection pooling support, written in Rust.
Features
- HTTP/HTTPS Proxy Support: Handle both HTTP and HTTPS (CONNECT method) requests
- Connection Pooling: Reuse TCP connections for better performance
- Configurable: Command-line interface with customizable host, port, and logging options
- Async: Built on Tokio for high-performance asynchronous I/O
- Library + Binary: Can be used as both a standalone binary and a Rust library
- Apache 2.0 Licensed: Open source under Apache License 2.0
Installation
From Source
From Crates.io
As a Library
Add this to your Cargo.toml:
[]
= "0.1.0"
Quick Start
Command Line Usage
# Start proxy server on default port 3128
# Custom host and port
# Enable verbose logging
# Show help
Library Usage
use ;
use SocketAddr;
async
Configuration
Command Line Options
USAGE:
easy-http-proxy-server [OPTIONS]
OPTIONS:
--host <HOST> Host to bind to [default: 127.0.0.1]
-p, --port <PORT> Port to bind to [default: 3128]
-v, --verbose Enable verbose logging
-h, --help Print help information
Environment Variables
RUST_LOG: Set logging level (e.g.,RUST_LOG=debug)
API Documentation
ProxyServer
The main proxy server struct that handles incoming connections.
ProxyConfig
Configuration for the proxy server.
ConnectionPool
Connection pool for managing reusable TCP connections.
Error Handling
The library uses a custom ProxyError enum for consistent error handling:
Architecture
The proxy server consists of several key components:
- ProxyServer: Main server that accepts connections and spawns handlers
- ConnectionPool: Manages reusable TCP connections to improve performance
- Request Handlers: Separate handlers for HTTP and HTTPS (CONNECT) requests
- Async I/O: Built on Tokio for high-performance asynchronous networking
HTTP Proxy Flow
- Client connects to proxy server
- Proxy server parses HTTP request
- For HTTP requests: Proxy server forwards request to target server and relays response
- For HTTPS requests: Proxy server establishes CONNECT tunnel and relays encrypted data
Connection Pooling
- TCP connections are pooled and reused for better performance
- Connections are automatically cleaned up when expired
- Thread-safe implementation using Arc and Mutex
Performance
- Connection Pooling: Reuses TCP connections to reduce connection overhead
- Async I/O: Non-blocking I/O operations using Tokio
- Zero-copy: Efficient data transfer where possible
- Memory Efficient: Minimal memory footprint with efficient data structures
Security Considerations
- No authentication mechanisms currently implemented
- No rate limiting or request filtering
- Basic proxy functionality without access controls
- Suitable for development and testing environments
Limitations
- The current implementation uses
Connection: closeheaders, which means connections are not actually reused in practice - Basic connection pooling without advanced features like connection limits or health checks
- No authentication or access control mechanisms
- Limited error recovery and retry logic
- HTTP/1.1 only (no HTTP/2 support)
Development
Building
# Debug build
# Release build
# Run tests
# Run with logging
RUST_LOG=debug
Testing
# Run all tests
# Run library tests only
# Run documentation tests
# Run with verbose output
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Copyright 2024
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Changelog
v0.1.0
- Initial release
- HTTP/HTTPS proxy support
- Connection pooling
- Command-line interface
- Library API
Future Improvements
- Implement proper HTTP/1.1 connection reuse
- Add connection pool configuration options
- Implement connection health checking
- Add support for HTTP/2
- Add authentication mechanisms
- Implement request/response logging and metrics
- Add support for proxy chaining
- Implement rate limiting and throttling
- Add WebSocket support
- Implement request filtering and blocking
- Add SSL/TLS termination support
Support
If you encounter any issues or have questions, please file an issue on the issue tracker.