pub struct Context {
pub req: Request,
/* private fields */
}Expand description
Context holds request data and provides response building methods
Fields§
§req: RequestImplementations§
Source§impl Context
impl Context
Sourcepub async fn new(req: HyperRequest<Incoming>, params: Params) -> Result<Self>
pub async fn new(req: HyperRequest<Incoming>, params: Params) -> Result<Self>
Create a new context from a request and params
Sourcepub async fn set(&self, key: impl Into<String>, value: impl Into<String>)
pub async fn set(&self, key: impl Into<String>, value: impl Into<String>)
Set a value in the context state (shared between middleware)
Read a request cookie by name.
All request cookies.
Queue a Set-Cookie for the response. Errors if the cookie is invalid.
Queue a deletion of the named cookie (Max-Age=0).
Sourcepub fn peer_addr(&self) -> Option<SocketAddr>
pub fn peer_addr(&self) -> Option<SocketAddr>
The peer address of the underlying connection, if known. This is the
direct socket peer — for the originating client behind a proxy, use
client_ip.
Sourcepub fn client_ip(&self) -> Option<IpAddr>
pub fn client_ip(&self) -> Option<IpAddr>
Best-effort originating client IP.
When proxy trust is enabled (app.trust_proxy(true)) this honors the
left-most X-Forwarded-For entry, then Forwarded: for=…; otherwise (or
if no such header) it falls back to the connection peer. Only enable
proxy trust when the app is actually behind a trusted proxy — these
headers are client-spoofable.