Skip to main content

RawHead

Struct RawHead 

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

The bytes of a head and the spans of its parts, all relative to bytes: what RequestHead::raw and ResponseHead::raw return.

The bytes run from the first byte the connection kept for the message (any empty lines a client sent before the request line, which RFC 9112 section 2.2 lets a server skip, are included) to the end of the blank line that ends the head. Spans for parts a head does not have are empty: status on a request, method and target on a response.

Debug shows lengths and spans only, never the bytes, so a raw head in a log cannot leak a credential.

§Examples

use http_net::{ServerConn, ServerEvent};

let mut conn = ServerConn::new();
let _ = conn.feed(b"GET /a HTTP/1.1\r\nHost: x\r\n\r\nbody bytes are not part of it");
let ServerEvent::Request(req) = conn.poll().unwrap() else { panic!() };
let raw = req.raw();
assert_eq!(raw.bytes(), b"GET /a HTTP/1.1\r\nHost: x\r\n\r\n");
assert_eq!(raw.method().get(raw.bytes()), b"GET");
assert_eq!(raw.target().get(raw.bytes()), b"/a");
assert_eq!(raw.version().get(raw.bytes()), b"HTTP/1.1");
assert!(raw.status().is_empty());
assert_eq!(raw.fields().len(), 1);

Implementations§

Source§

impl<'a> RawHead<'a>

Source

pub fn bytes(&self) -> &'a [u8] ⓘ

The head bytes, from its first byte to the end of the blank line.

§Examples

See RawHead.

Source

pub fn start_line(&self) -> Span

The request line or status line, without its CRLF.

§Examples
let raw = req.raw();
assert_eq!(raw.start_line().get(raw.bytes()), b"GET / HTTP/1.1");
Source

pub fn method(&self) -> Span

The method (requests; empty for a response).

§Examples

See RawHead.

Source

pub fn target(&self) -> Span

The request target (requests; empty for a response).

§Examples

See RawHead.

Source

pub fn version(&self) -> Span

The protocol version, HTTP/1.1 or HTTP/1.0 as received.

§Examples

See RawHead.

Source

pub fn status(&self) -> Span

The three status digits (responses; empty for a request).

§Examples
let raw = resp.raw();
assert_eq!(raw.status().get(raw.bytes()), b"404");
assert!(raw.method().is_empty());
Source

pub fn fields(&self) -> &'a [FieldSpan]

Every field line’s name and value spans, in arrival order.

§Examples

See FieldSpan.

Trait Implementations§

Source§

impl<'a> Clone for RawHead<'a>

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<'a> Copy for RawHead<'a>

Source§

impl Debug for RawHead<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for RawHead<'a>

§

impl<'a> RefUnwindSafe for RawHead<'a>

§

impl<'a> Send for RawHead<'a>

§

impl<'a> Sync for RawHead<'a>

§

impl<'a> Unpin for RawHead<'a>

§

impl<'a> UnsafeUnpin for RawHead<'a>

§

impl<'a> UnwindSafe for RawHead<'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 = !

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.