Skip to main content

RequestContext

Struct RequestContext 

Source
pub struct RequestContext<'a> {
    pub method: &'a str,
    pub uri: &'a str,
    pub body: Option<&'a [u8]>,
    pub headers: &'a [(&'a str, &'a str)],
    pub peer_addr: Option<SocketAddr>,
}
Expand description

The request fields the Digest response hash covers (RFC 7616 §3.4.1 / RFC 2326 §14): the method, the request URI, and — for qop=auth-int — the body. Also carries the request’s headers and transport peer address, so a server-side crate::Verifier scheme can see beyond the Authorization header — e.g. a reverse-proxy forwarded-auth scheme reading X-Forwarded-User/X-Forwarded-For (issue #663 extensibility wave part 1). Client-side use (crate::respond/crate::Authenticator) needs neither field; Self::new defaults both to empty/None.

The uri is scheme-specific: an HTTP absolute/relative URL for HTTP clients, or the RTSP request URI (e.g. rtsp://host/stream) for RTSP — never translate one into the other (RFC 2326 §14).

Fields§

§method: &'a str

The request method ("GET", "DESCRIBE", …).

§uri: &'a str

The request URI, in the caller’s protocol’s own form.

§body: Option<&'a [u8]>

The request body, needed only for Digest qop=auth-int. Some(&[]) for a bodyless request still lets auth-int be computed.

§headers: &'a [(&'a str, &'a str)]

Every request header, as (name, value) pairs — Self::header looks one up case-insensitively (header names are case-insensitive, RFC 7230 §3.2). Empty for client-side use (Self::new’s default): a client answering a challenge computes Authorization from method/uri/body alone. Server-side (crate::Verifier::verify) this is how every scheme — including a future one — reads whatever header it needs, not just Authorization.

§peer_addr: Option<SocketAddr>

The transport-layer peer address (e.g. the accepted TCP connection’s remote address), if the caller has one to attach. This is the actual connection peer — which, behind a reverse proxy, is the proxy itself, not the original client (see X-Forwarded-For in Self::headers for that). None for client-side use and whenever the caller has no transport peer to attach.

Implementations§

Source§

impl<'a> RequestContext<'a>

Source

pub fn new(method: &'a str, uri: &'a str) -> RequestContext<'a>

Builds a context for a bodyless request with no headers/peer attached (the common client-side case) — use Self::with_headers/ Self::with_peer_addr to attach either.

Source

pub fn with_body(self, body: &'a [u8]) -> RequestContext<'a>

Attaches a request body (for qop=auth-int).

Source

pub fn with_headers( self, headers: &'a [(&'a str, &'a str)], ) -> RequestContext<'a>

Attaches the request’s headers (server-side use — see Self::headers).

Source

pub fn with_peer_addr(self, peer_addr: SocketAddr) -> RequestContext<'a>

Attaches the transport peer address (server-side use — see Self::peer_addr).

Source

pub fn header(&self, name: &str) -> Option<&'a str>

Looks up a header by name, case-insensitively (RFC 7230 §3.2). Returns the first match if Self::headers carries more than one with the same name.

Trait Implementations§

Source§

impl<'a> Clone for RequestContext<'a>

Source§

fn clone(&self) -> RequestContext<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for RequestContext<'a>

Source§

impl Debug for RequestContext<'_>

Manual Debug (rather than #[derive(Debug)]): Self::headers carries whatever the caller attached, which — server-side — includes the real Authorization/Proxy-Authorization header the request was authenticated with. Basic’s value is a reversible base64 user:pass (RFC 7617 §2); a bare tracing::debug!(?ctx, ...) call must not dump it to logs. Every other header (name and value) is rendered normally — only the value of an auth header is redacted, and only that header’s name is enough to tell which one.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for RequestContext<'a>

§

impl<'a> RefUnwindSafe for RequestContext<'a>

§

impl<'a> Send for RequestContext<'a>

§

impl<'a> Sync for RequestContext<'a>

§

impl<'a> Unpin for RequestContext<'a>

§

impl<'a> UnsafeUnpin for RequestContext<'a>

§

impl<'a> UnwindSafe for RequestContext<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V