Skip to main content

Delivery

Struct Delivery 

Source
pub struct Delivery<'a> { /* private fields */ }
Expand description

One delivery from a provider, exactly as it arrived.

Headers and bytes, and nothing parsed: a signature is over the bytes the provider sent, and a body that has been through a JSON parser and back is a different sequence of bytes that will not verify. A web framework hands the body over as &[u8] before anything else touches it, and that is what belongs here.

Header names are matched without regard to case, because HTTP/2 lowercases them and HTTP/1.1 does not.

Implementations§

Source§

impl<'a> Delivery<'a>

Source

pub const fn new(headers: &'a [(&'a str, &'a str)], body: &'a [u8]) -> Self

Holds a delivery’s headers and its body.

Source

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

The first header with this name, ignoring case.

For anything a signature depends on, use Delivery::signed_header instead: this one answers the first of two and says nothing about the second.

Source

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

The header with this name, refusing a delivery that carries two.

Ok(None) is a delivery that carries none, which is the caller’s own error to phrase — a header that is merely absent and one that is contradicted are different failures and deserve different words.

§Why this exists

A signature is a claim about one delivery, and two headers making that claim are two claims. Whichever a verifier picks, something in front of it — a proxy, a load balancer, whatever wrote the second — picked differently, and the pair of them no longer agree about what was signed. That disagreement is the whole of a header-smuggling attack, and the only safe reading of it is that this delivery cannot be trusted.

It costs nothing to refuse: no provider here sends a signature header twice, so a delivery that carries two did not come from them intact.

Source

pub const fn headers(&self) -> &'a [(&'a str, &'a str)]

Every header, in the order they arrived.

Source

pub const fn body(&self) -> &'a [u8]

The body as it arrived.

Source

pub fn body_str(&self) -> Option<&'a str>

The body as text, for a provider that posts a form or JSON.

None for a body that is not UTF-8. Nothing lossy: a body that is not what the provider documents is one to refuse rather than repair.

Trait Implementations§

Source§

impl<'a> Clone for Delivery<'a>

Source§

fn clone(&self) -> Delivery<'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 Delivery<'a>

Source§

impl<'a> Debug for Delivery<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Delivery<'a>

§

impl<'a> RefUnwindSafe for Delivery<'a>

§

impl<'a> Send for Delivery<'a>

§

impl<'a> Sync for Delivery<'a>

§

impl<'a> Unpin for Delivery<'a>

§

impl<'a> UnsafeUnpin for Delivery<'a>

§

impl<'a> UnwindSafe for Delivery<'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<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> 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.