Struct http_parser::HttpParser [] [src]

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,
    // some fields omitted
}

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

HTTP version of the request or response

errno

Error number of there is an error in parsing

status_code

Status code of the response

method

HTTP method of the request

upgrade

whether the protocol is upgraded

strict

whether using strict parsing mode

Methods

impl HttpParser

fn new(tp: HttpParserType) -> HttpParser

Creates a parser of the specified type.

Example

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

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());

fn http_body_is_final(&self) -> bool

Returns true if the HTTP body is final.

fn pause(&mut self, pause: bool)

Pauses the parser.

fn http_should_keep_alive(&self) -> bool

Returns true if it needs to keep alive.