pub struct ClientAddress { /* private fields */ }Expand description
The client address the proxy resolved for a request.
A request extension on every request the proxy serves: an
AuthDecider and an
ExtraRouteHandler get it in their
request view, a fallback and a tonic upstream in process read it with
request.extensions().get::<ClientAddress>(). The connection’s own record
(Request::remote_addr, Request::peer_certs) stays as it is.
§Examples
use structured_proxy::client_address::{ClientAddress, Resolution};
// What a tonic handler behind the proxy does with it.
fn caller(request: &tonic::Request<()>) -> Option<std::net::IpAddr> {
request.extensions().get::<ClientAddress>()?.ip()
}
let client = ClientAddress::from_peer(Some("203.0.113.7:51234".parse().unwrap()));
assert_eq!(client.resolution(), Resolution::Peer("203.0.113.7".parse().unwrap()));
let mut request = tonic::Request::new(());
request.extensions_mut().insert(client);
assert_eq!(caller(&request), Some("203.0.113.7".parse().unwrap()));Implementations§
Source§impl ClientAddress
impl ClientAddress
Sourcepub fn from_peer(peer: Option<SocketAddr>) -> Self
pub fn from_peer(peer: Option<SocketAddr>) -> Self
The address of a request from peer through no trusted proxy: the
peer itself, or Resolution::Unavailable without one. The view a
hook’s own tests hand it.
Sourcepub fn peer(&self) -> Option<SocketAddr>
pub fn peer(&self) -> Option<SocketAddr>
The connection’s peer: the client, or the last proxy before this one.
Sourcepub fn resolution(&self) -> Resolution
pub fn resolution(&self) -> Resolution
How the address was resolved, or why it was not.
Trait Implementations§
Source§impl Clone for ClientAddress
impl Clone for ClientAddress
Source§impl Debug for ClientAddress
impl Debug for ClientAddress
impl Eq for ClientAddress
Source§impl PartialEq for ClientAddress
impl PartialEq for ClientAddress
impl StructuralPartialEq for ClientAddress
Auto Trait Implementations§
impl !Freeze for ClientAddress
impl RefUnwindSafe for ClientAddress
impl Send for ClientAddress
impl Sync for ClientAddress
impl Unpin for ClientAddress
impl UnsafeUnpin for ClientAddress
impl UnwindSafe for ClientAddress
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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>
Wrap the input message
T in a tonic::Request