Skip to main content

OwnedRequestHead

Struct OwnedRequestHead 

Source
pub struct OwnedRequestHead { /* private fields */ }
Expand description

A request head that owns its bytes and spans: from RequestHead::to_owned, or rebuilt from a passport’s parts with from_parts. Debug shows the head the way RequestHead does, credential values redacted.

§Examples

See RequestHead::to_owned and HeadFacts.

Implementations§

Source§

impl OwnedRequestHead

Source

pub fn view(&self) -> RequestHead<'_>

A view of the owned head, with every accessor of a borrowed one.

§Examples

See RequestHead::to_owned.

Source

pub fn from_parts( bytes: Vec<u8>, fields: Vec<FieldSpan>, facts: HeadFacts, ) -> Result<Self, HttpError>

Rebuilds an owned head from copied parts (RequestHead::copy_into), checking first that they still describe one head: every span lies inside bytes, the start line and every field line have the structure the parser accepted (method, target, and version where the facts say, each field name a token followed by a colon, each value without control bytes or surrounding whitespace, the lines in order and back to back, the blank line last), and the host and target spans in the facts point where they should. A passport buffer that was changed is refused, never read.

The framing facts themselves (body length, keep-alive) are taken as given: they come from the same trusted copy, and recomputing them would be the parse this is meant to avoid.

§Errors

HttpError::InvalidState, naming the first rule that failed.

§Examples
use http_net::{HttpError, OwnedRequestHead, ServerConn, ServerEvent};

let mut conn = ServerConn::new();
let _ = conn.feed(b"GET / HTTP/1.1\r\nHost: a\r\n\r\n");
let ServerEvent::Request(req) = conn.poll().unwrap() else { panic!() };
let (mut bytes, mut fields) = (Vec::new(), Vec::new());
let facts = req.copy_into(&mut bytes, &mut fields)?;
bytes[16] = b' '; // the first field name now starts with a space
assert!(matches!(
    OwnedRequestHead::from_parts(bytes, fields, facts),
    Err(HttpError::InvalidState(_))
));
Source

pub fn into_parts(self) -> (Vec<u8>, Vec<FieldSpan>, HeadFacts)

Gives the parts back, so a passport pool can reuse the vectors for the next head without allocating.

§Examples
use http_net::{ServerConn, ServerEvent};

let mut conn = ServerConn::new();
let _ = conn.feed(b"GET /a HTTP/1.1\r\nHost: a\r\n\r\n");
let ServerEvent::Request(req) = conn.poll().unwrap() else { panic!() };
let (mut bytes, mut fields, _facts) = req.to_owned().into_parts();
let capacity = bytes.capacity();
bytes.clear();
fields.clear();
assert_eq!(bytes.capacity(), capacity);

Trait Implementations§

Source§

impl Clone for OwnedRequestHead

Source§

fn clone(&self) -> Self

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 Debug for OwnedRequestHead

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for OwnedRequestHead

Source§

impl PartialEq for OwnedRequestHead

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for OwnedRequestHead

Auto Trait Implementations§

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.