Struct HttpParser

Source
pub struct HttpParser {
    pub http_version: HttpVersion,
    pub errno: Option<HttpErrno>,
    pub status_code: Option<u16>,
    pub method: Option<HttpMethod>,
    pub upgrade: bool,
    pub strict: bool,
    /* private fields */
}
Expand description

The HTTP parser that parses requests and responses.

§Example

struct Callback;

impl HttpParserCallback for Callback {
    fn on_message_begin(&mut self, parser: &mut HttpParser) -> CallbackResult {
        println!("Message begin");
        Ok(ParseAction::None)
    }

    // Override other functions as you wish
}

let mut parser = HttpParser::new(HttpParserType::Request);

let mut cb = Callback;

let line: &str = "GET / HTTP/1.1\r\n";
parser.execute(&mut cb, line.as_bytes());

Fields§

§http_version: HttpVersion

HTTP version of the request or response

§errno: Option<HttpErrno>

Error number of there is an error in parsing

§status_code: Option<u16>

Status code of the response

§method: Option<HttpMethod>

HTTP method of the request

§upgrade: bool

whether the protocol is upgraded

§strict: bool

whether using strict parsing mode

Implementations§

Source§

impl HttpParser

Source

pub fn new(tp: HttpParserType) -> HttpParser

Creates a parser of the specified type.

§Example
let mut parser = HttpParser::new(HttpParserType::Request);
Source

pub fn execute<T: HttpParserCallback>( &mut self, cb: &mut T, data: &[u8], ) -> usize

Parses the HTTP requests or responses, specified in data as an array of bytes.

§Example
let mut parser = HttpParser::new(HttpParserType::Request);

let mut cb = Callback;

let line: &str = "GET / HTTP/1.1\r\n";
parser.execute(&mut cb, line.as_bytes());
Source

pub fn http_body_is_final(&self) -> bool

Returns true if the HTTP body is final.

Source

pub fn pause(&mut self, pause: bool)

Pauses the parser.

Source

pub fn http_should_keep_alive(&self) -> bool

Returns true if it needs to keep alive.

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, 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.