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 of the request or response

Error number of there is an error in parsing

Status code of the response

HTTP method of the request

whether the protocol is upgraded

whether using strict parsing mode

Methods

impl HttpParser
[src]

Creates a parser of the specified type.

Example

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

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

Returns true if the HTTP body is final.

Pauses the parser.

Returns true if it needs to keep alive.