#[non_exhaustive]pub enum ClientAddress {
Peer(IpAddr),
Forwarded {
addr: IpAddr,
hops: u8,
},
Unknown {
hops: u8,
},
}Expand description
The client address a request is attributed to.
§Examples
use core::net::IpAddr;
use parse_net::{client_address, ClientAddress, ForwardedSource};
let peer: IpAddr = "10.0.0.1".parse()?;
let trusted = |a: IpAddr| a == peer;
let hidden: [&[u8]; 1] = [b"for=unknown"];
assert_eq!(client_address(peer, ForwardedSource::Forwarded(&hidden), &trusted, 16)?, ClientAddress::Unknown { hops: 1 });
let none: [&[u8]; 0] = [];
assert_eq!(client_address(peer, ForwardedSource::XForwardedFor(&none), &trusted, 16)?, ClientAddress::Peer(peer));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Peer(IpAddr)
The connection’s peer: it is not a trusted proxy (its header was not read), or it is a trusted proxy that forwarded no chain.
Forwarded
An address from the chain, found after walking hops elements from
the right.
Unknown
The walk reached unknown, an obfuscated identifier, or an element
without for after hops elements: nothing to its left can be
trusted.
Trait Implementations§
Source§impl Clone for ClientAddress
impl Clone for ClientAddress
impl Copy for ClientAddress
Source§impl Debug for ClientAddress
impl Debug for ClientAddress
impl Eq for ClientAddress
Source§impl Hash for ClientAddress
impl Hash for ClientAddress
Source§impl PartialEq for ClientAddress
impl PartialEq for ClientAddress
impl StructuralPartialEq for ClientAddress
Auto Trait Implementations§
impl Forget for ClientAddress
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