pub struct RemoteIp(pub Option<IpAddr>);Expand description
Extractor for the client’s IP address, from Cloudflare’s CF-Connecting-IP header.
Cloudflare sets CF-Connecting-IP on every request that reaches a Worker
and replaces any value the client sent, so it can be trusted, unlike
X-Forwarded-For (Rails’ request.remote_ip, Loco’s RemoteIP). It is
RemoteIp(None) only when the header is missing or malformed, e.g. in unit
tests that build requests by hand. Never rejects. Use it to key rate limits
or to record where a sign-in came from; it is personal data under the GDPR.
§Examples
use ocre::RemoteIp;
async fn whoami(RemoteIp(ip): RemoteIp) -> String {
ip.map_or_else(|| "unknown".to_owned(), |ip| ip.to_string())
}Tuple Fields§
§0: Option<IpAddr>Trait Implementations§
impl Copy for RemoteIp
impl Eq for RemoteIp
Source§impl<S: Send + Sync> FromRequestParts<S> for RemoteIp
impl<S: Send + Sync> FromRequestParts<S> for RemoteIp
Source§type Rejection = Infallible
type Rejection = Infallible
If the extractor fails it’ll use this “rejection” type. A rejection is
a kind of error that can be converted into a response.
Source§async fn from_request_parts(
parts: &mut Parts,
_state: &S,
) -> Result<Self, Self::Rejection>
async fn from_request_parts( parts: &mut Parts, _state: &S, ) -> Result<Self, Self::Rejection>
Perform the extraction.
impl StructuralPartialEq for RemoteIp
Auto Trait Implementations§
impl Freeze for RemoteIp
impl RefUnwindSafe for RemoteIp
impl Send for RemoteIp
impl Sync for RemoteIp
impl Unpin for RemoteIp
impl UnsafeUnpin for RemoteIp
impl UnwindSafe for RemoteIp
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.§impl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
§type Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
If the extractor fails it’ll use this “rejection” type. A rejection is
a kind of error that can be converted into a response.
§fn from_request(
req: Request<Body>,
state: &S,
) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
Perform the extraction.