axum-reverse-proxy
A flexible and efficient reverse proxy implementation for Axum web applications. This library provides a simple way to forward HTTP requests from your Axum application to upstream servers.
Features
- 🛣️ Path-based routing
- 🔄 Automatic retry mechanism with exponential backoff
- 📨 Header forwarding (with host header management)
- ⚙️ Configurable HTTP client settings
- 🔌 Easy integration with Axum's Router
- 🧰 Custom client configuration support
- 🔒 HTTPS support
Installation
Add this to your Cargo.toml
:
[]
= "0.1.0"
Quick Start
Here's a simple example that forwards all requests under /api
to httpbin.org
:
use Router;
use ReverseProxy;
// Create a reverse proxy that forwards requests from /api to httpbin.org
let proxy = new;
// Convert the proxy to a router and use it in your Axum application
let app: Router = proxy.into;
Advanced Usage
Merging with Existing Router
You can merge the proxy with your existing Axum router:
use ;
use ReverseProxy;
async
let app: = new
.route
.merge
.with_state;
Custom Client Configuration
For more control over the HTTP client behavior:
use ReverseProxy;
use ;
use Body;
let mut connector = new;
connector.set_nodelay;
connector.enforce_http;
connector.set_keepalive;
let client = builder
.pool_idle_timeout
.pool_max_idle_per_host
.build;
let proxy = new_with_client;
Configuration
The default configuration includes:
- 3 retry attempts with exponential backoff
- 60-second keepalive timeout
- 10-second connect timeout
- TCP nodelay enabled
- Connection pooling with 32 idle connections per host
- Automatic host header management
Examples
Check out the examples directory for more usage examples:
- Basic Proxy - Shows how to set up a basic reverse proxy with path-based routing
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.