pub struct ClientAddressLayer { /* private fields */ }Expand description
Resolves the client address of every request before the service it wraps
sees it: puts the ClientAddress on the request and rewrites its
forwarding headers, as the proxy does before its own guards.
The proxy applies it itself. Use it in a router of your own that mounts
proxy parts such as the shield middleware directly, so
they key by the client behind your trusted proxies rather than by the
proxies’ own address. The peer comes from the ConnectInfo<SocketAddr> an
axum server records (into_make_service_with_connect_info) or the
TcpConnectInfo a tonic server does; without one the address is
Resolution::Unavailable. required is not enforced
here: read ClientAddress::resolution where it matters.
§Examples
use structured_proxy::client_address::ClientAddressLayer;
use structured_proxy::config::ClientAddressConfig;
let mut trust = ClientAddressConfig::default();
trust.trusted_proxies = vec!["10.0.0.0/8".into()];
let app: axum::Router = axum::Router::new()
.route("/", axum::routing::get(|| async { "ok" }))
.layer(ClientAddressLayer::new(&trust).unwrap());Implementations§
Source§impl ClientAddressLayer
impl ClientAddressLayer
Sourcepub fn new(config: &ClientAddressConfig) -> Result<Self>
pub fn new(config: &ClientAddressConfig) -> Result<Self>
The resolution config describes.
§Errors
A trusted_proxies entry that is neither a CIDR range nor an address.
Trait Implementations§
Source§impl Clone for ClientAddressLayer
impl Clone for ClientAddressLayer
Source§impl Debug for ClientAddressLayer
impl Debug for ClientAddressLayer
Source§impl<S> Layer<S> for ClientAddressLayer
impl<S> Layer<S> for ClientAddressLayer
Source§type Service = ClientAddressService<S>
type Service = ClientAddressService<S>
Source§fn layer(&self, inner: S) -> ClientAddressService<S>
fn layer(&self, inner: S) -> ClientAddressService<S>
Auto Trait Implementations§
impl Freeze for ClientAddressLayer
impl RefUnwindSafe for ClientAddressLayer
impl Send for ClientAddressLayer
impl Sync for ClientAddressLayer
impl Unpin for ClientAddressLayer
impl UnsafeUnpin for ClientAddressLayer
impl UnwindSafe for ClientAddressLayer
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request