| Crates.io | easy-http-proxy-server |
| lib.rs | easy-http-proxy-server |
| version | 0.0.1 |
| created_at | 2025-09-29 02:51:13.26981+00 |
| updated_at | 2025-09-29 02:51:13.26981+00 |
| description | A simple HTTP/HTTPS proxy server with connection pooling support |
| homepage | |
| repository | https://gitee.com/awol2010ex/easy-http-proxy-server |
| max_upload_size | |
| id | 1858840 |
| size | 67,722 |
A simple HTTP/HTTPS proxy server with connection pooling support, written in Rust.
git clone https://github.com/yourusername/easy-http-proxy-server.git
cd easy-http-proxy-server
cargo build --release
cargo install easy-http-proxy-server
Add this to your Cargo.toml:
[dependencies]
easy-http-proxy-server = "0.1.0"
# Start proxy server on default port 3128
cargo run --bin easy-http-proxy-server
# Custom host and port
cargo run --bin easy-http-proxy-server -- --host 0.0.0.0 --port 8080
# Enable verbose logging
cargo run --bin easy-http-proxy-server -- --verbose
# Show help
cargo run --bin easy-http-proxy-server -- --help
use easy_http_proxy_server::{ProxyServer, ProxyConfig};
use std::net::SocketAddr;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let addr: SocketAddr = "127.0.0.1:3128".parse()?;
let config = ProxyConfig::new(addr, true);
let server = ProxyServer::new(config);
println!("Starting proxy server on {}", addr);
server.run().await?;
Ok(())
}
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
RUST_LOG: Set logging level (e.g., RUST_LOG=debug)The main proxy server struct that handles incoming connections.
pub struct ProxyServer {
// ...
}
impl ProxyServer {
/// Create a new proxy server with the given configuration
pub fn new(config: ProxyConfig) -> Self;
/// Create a new proxy server with custom connection pool
pub fn with_pool(config: ProxyConfig, pool: ConnectionPool) -> Self;
/// Run the proxy server (blocks indefinitely)
pub async fn run(&self) -> Result<()>;
/// Get total connections handled
pub fn total_connections(&self) -> u64;
/// Get total requests handled
pub fn total_requests(&self) -> u64;
/// Get connection pool reference
pub fn connection_pool(&self) -> &Arc<ConnectionPool>;
}
Configuration for the proxy server.
pub struct ProxyConfig {
pub addr: SocketAddr,
pub verbose: bool,
}
impl ProxyConfig {
/// Create a new proxy configuration
pub fn new(addr: SocketAddr, verbose: bool) -> Self;
/// Create a configuration with default address
pub fn localhost(port: u16, verbose: bool) -> Self;
}
Connection pool for managing reusable TCP connections.
pub struct ConnectionPool {
// ...
}
impl ConnectionPool {
/// Create a new connection pool
pub fn new() -> Self;
/// Get or create a connection to the specified address
pub async fn get_or_create(&self, addr: &str) -> Result<TcpStream>;
/// Get a connection from the pool if available
pub async fn get(&self, addr: &str) -> Option<TcpStream>;
/// Put a connection back into the pool
pub async fn put(&self, addr: String, stream: TcpStream);
/// Clean up expired connections
pub async fn cleanup_expired(&self);
}
The library uses a custom ProxyError enum for consistent error handling:
pub enum ProxyError {
Io(std::io::Error),
Hyper(hyper::Error),
AddressParse(std::net::AddrParseError),
Other(String),
}
The proxy server consists of several key components:
Connection: close headers, which means connections are not actually reused in practice# Debug build
cargo build
# Release build
cargo build --release
# Run tests
cargo test
# Run with logging
RUST_LOG=debug cargo run
# Run all tests
cargo test
# Run library tests only
cargo test --lib
# Run documentation tests
cargo test --doc
# Run with verbose output
cargo test -- --nocapture
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.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)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.
If you encounter any issues or have questions, please file an issue on the issue tracker.