Skip to main content

RequestReader

Struct RequestReader 

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

Sans-IO HTTP/1.x request parser.

§Usage

use nexus_web::http::RequestReader;

let mut reader = RequestReader::new(4096);
reader.read(b"GET / HTTP/1.1\r\nHost: example.com\r\n\r\n").unwrap();
let req = reader.next().unwrap().unwrap();
assert_eq!(req.method, "GET");
assert_eq!(req.path, "/");
assert_eq!(req.header("Host"), Some("example.com"));

Implementations§

Source§

impl RequestReader

Source

pub fn new(capacity: usize) -> Self

Create with the given buffer capacity.

Source

pub fn max_headers(self, n: usize) -> Self

Set maximum number of headers. Default: 64.

Source

pub fn max_head_size(self, n: usize) -> Self

Set maximum head size. Default: 8KB.

Source

pub fn spare(&mut self) -> &mut [u8]

Writable region for direct in-buffer writes. Pair with filled() to commit bytes after the write. Used by crate::WireStream to deliver bytes from a transport without a slice intermediate.

Source

pub fn filled(&mut self, n: usize)

Commit n bytes written into spare().

Source

pub fn read(&mut self, src: &[u8]) -> Result<(), HttpError>

Buffer wire bytes.

Source

pub fn next(&mut self) -> Result<Option<Request<'_>>, HttpError>

Parse the next request.

Returns Ok(Some(request)) when the head is complete. Returns Ok(None) if more bytes are needed.

Source

pub fn remainder(&self) -> &[u8]

Bytes after the parsed head.

Source

pub fn reset(&mut self)

Reset for a new request.

Trait Implementations§

Source§

impl ParserSink for RequestReader

Lets a WireStream feed bytes directly into the RequestReader’s spare region — one fewer copy than going through a slice intermediary.

Source§

fn spare(&mut self) -> &mut [u8]

Writable region where new bytes go.
Source§

fn filled(&mut self, n: usize)

Commit n bytes written into spare(). Read more

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> 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> Same for T

Source§

type Output = T

Should always be Self
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