pub struct ReverseProxy { /* private fields */ }
Expand description
A reverse proxy that forwards HTTP requests to an upstream server.
The ReverseProxy
struct handles the forwarding of HTTP requests from a specified path
to a target upstream server. It manages its own HTTP client with configurable settings
for connection pooling, timeouts, and retries.
Implementations§
Source§impl ReverseProxy
impl ReverseProxy
Sourcepub fn new<S>(path: S, target: S) -> Self
pub fn new<S>(path: S, target: S) -> Self
Creates a new ReverseProxy
instance with default client settings.
§Arguments
path
- The base path to match incoming requests against (e.g., “/api”)target
- The upstream server URL to forward requests to (e.g., “https://api.example.com”)
§Example
use axum_reverse_proxy::ReverseProxy;
let proxy = ReverseProxy::new("/api", "https://api.example.com");
Sourcepub fn new_with_client<S>(
path: S,
target: S,
client: Client<HttpConnector, Body>,
) -> Self
pub fn new_with_client<S>( path: S, target: S, client: Client<HttpConnector, Body>, ) -> Self
Creates a new ReverseProxy
instance with a custom HTTP client.
This method allows for more fine-grained control over the proxy behavior by accepting a pre-configured HTTP client.
§Arguments
path
- The base path to match incoming requests againsttarget
- The upstream server URL to forward requests toclient
- A custom-configured HTTP client
§Example
use axum_reverse_proxy::ReverseProxy;
use hyper_util::client::legacy::{Client, connect::HttpConnector};
use axum::body::Body;
let client = Client::builder(hyper_util::rt::TokioExecutor::new())
.build(HttpConnector::new());
let proxy = ReverseProxy::new_with_client("/api", "https://api.example.com", client);
Trait Implementations§
Source§impl Clone for ReverseProxy
impl Clone for ReverseProxy
Source§fn clone(&self) -> ReverseProxy
fn clone(&self) -> ReverseProxy
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<S> From<ReverseProxy> for Router<S>
Enables conversion from a ReverseProxy
into an Axum Router
.
impl<S> From<ReverseProxy> for Router<S>
Enables conversion from a ReverseProxy
into an Axum Router
.
This implementation allows the reverse proxy to be easily integrated into an Axum application. It handles:
- Path-based routing using the configured base path
- State management using
Arc
for thread-safety - Fallback handling for all HTTP methods
§Example
use axum::Router;
use axum_reverse_proxy::ReverseProxy;
let proxy = ReverseProxy::new("/api", "https://api.example.com");
let app: Router = proxy.into();
Source§fn from(proxy: ReverseProxy) -> Self
fn from(proxy: ReverseProxy) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for ReverseProxy
impl !RefUnwindSafe for ReverseProxy
impl Send for ReverseProxy
impl Sync for ReverseProxy
impl Unpin for ReverseProxy
impl !UnwindSafe for ReverseProxy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more