#[non_exhaustive]pub struct Proxy<U, C>{
pub upstreams: U,
pub client: C,
pub url_path_getter: UrlPartGetter,
pub url_query_getter: UrlPartGetter,
pub host_header_getter: HostHeaderGetter,
pub client_ip_forwarding_enabled: bool,
pub strict_path_normalization_enabled: bool,
pub strip_authorization_header_enabled: bool,
}Expand description
Handler that can proxy request to other server.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.upstreams: UUpstreams list.
client: CClient for proxy.
url_path_getter: UrlPartGetterURL path getter.
url_query_getter: UrlPartGetterURL query getter.
host_header_getter: HostHeaderGetterHost header getter
client_ip_forwarding_enabled: boolFlag to enable x-forwarded-for header.
strict_path_normalization_enabled: boolFlag to reject ambiguous percent-encoded path characters before proxying.
Flag to drop the inbound Authorization header before forwarding.
Implementations§
Source§impl<U> Proxy<U, HyperClient<HttpsConnector<HttpConnector>>>
impl<U> Proxy<U, HyperClient<HttpsConnector<HttpConnector>>>
Sourcepub fn use_hyper_client(upstreams: U) -> Self
Available on crate feature hyper-client only.
pub fn use_hyper_client(upstreams: U) -> Self
hyper-client only.Create a new Proxy using the default Hyper client.
This is a convenient way to create a proxy with standard configuration.
Source§impl<U> Proxy<U, ReqwestClient>
impl<U> Proxy<U, ReqwestClient>
Sourcepub fn use_reqwest_client(upstreams: U) -> Self
Available on crate feature reqwest-client only.
pub fn use_reqwest_client(upstreams: U) -> Self
reqwest-client only.Create a new Proxy using the default Reqwest client.
This is a convenient way to create a proxy with standard configuration.
Source§impl<U> Proxy<U, UnixSockClient>
impl<U> Proxy<U, UnixSockClient>
Sourcepub fn use_unix_sock_tunnel(upstreams: U) -> Self
Available on crate feature unix-sock-client only.
pub fn use_unix_sock_tunnel(upstreams: U) -> Self
unix-sock-client only.Create a new Proxy that tunnels connections to a Unix socket.
Source§impl<U, C> Proxy<U, C>
impl<U, C> Proxy<U, C>
Sourcepub fn new(upstreams: U, client: C) -> Self
pub fn new(upstreams: U, client: C) -> Self
Creates a new Proxy with an upstream list.
The default host header getter is standard_host_header_getter, which forwards the
upstream host and includes a non-default port (RFC 7230 / RFC 9110). To forward only
the bare host name, configure default_host_header_getter via
Self::host_header_getter.
Sourcepub fn with_client_ip_forwarding(upstreams: U, client: C) -> Self
pub fn with_client_ip_forwarding(upstreams: U, client: C) -> Self
Creates a new Proxy with an upstream list and enables the x-forwarded-for header.
Client IP forwarding overwrites any inbound X-Forwarded-For value with the direct
client IP from the connection.
Sourcepub fn url_path_getter<G>(self, url_path_getter: G) -> Self
pub fn url_path_getter<G>(self, url_path_getter: G) -> Self
Set URL path getter.
Sourcepub fn url_query_getter<G>(self, url_query_getter: G) -> Self
pub fn url_query_getter<G>(self, url_query_getter: G) -> Self
Set URL query getter.
Sourcepub fn host_header_getter<G>(self, host_header_getter: G) -> Self
pub fn host_header_getter<G>(self, host_header_getter: G) -> Self
Set host header getter.
Sourcepub fn strict_path_normalization(self, enable: bool) -> Self
pub fn strict_path_normalization(self, enable: bool) -> Self
Enable or disable strict path normalization.
When enabled, the proxy rejects literal parent-directory (..) path components and paths
that still contain percent-encoded ., /, \, or % characters after Salvo routing has
extracted the path tail. This is useful when the proxy is used as a security boundary and
the upstream server may perform another decode or normalization pass.
Sourcepub fn upstreams_mut(&mut self) -> &mut U
pub fn upstreams_mut(&mut self) -> &mut U
Get upstreams mutable list.
Sourcepub fn client_mut(&mut self) -> &mut C
pub fn client_mut(&mut self) -> &mut C
Get client mutable reference.
Sourcepub fn client_ip_forwarding(self, enable: bool) -> Self
pub fn client_ip_forwarding(self, enable: bool) -> Self
Enable x-forwarded-for header forwarding.
When enabled, the proxy overwrites any inbound X-Forwarded-For value with the direct
client IP from the connection instead of trusting a client-supplied forwarding chain.
Drop the inbound Authorization header before forwarding the
request upstream.
Disabled by default to preserve the typical reverse-proxy pass-through behaviour. Enable this when the proxy sits in front of services that should not see the caller’s credentials — for example a public CORS gateway, a third-party API bridge, or any deployment where the upstream is in a different trust domain than the inbound client.
Trait Implementations§
Source§impl<U, C> Handler for Proxy<U, C>
impl<U, C> Handler for Proxy<U, C>
Source§fn handle<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
req: &'life1 mut Request,
depot: &'life2 mut Depot,
res: &'life3 mut Response,
_ctrl: &'life4 mut FlowCtrl,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
fn handle<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
req: &'life1 mut Request,
depot: &'life2 mut Depot,
res: &'life3 mut Response,
_ctrl: &'life4 mut FlowCtrl,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Source§fn arc(self) -> ArcHandlerwhere
Self: Sized,
fn arc(self) -> ArcHandlerwhere
Self: Sized,
ArcHandler.Source§fn hooped(self) -> HoopedHandlerwhere
Self: Sized,
fn hooped(self) -> HoopedHandlerwhere
Self: Sized,
HoopedHandler.