Crate http_parser

Source
Expand description

§The Rust HTTP Parser

The Rust HTTP Parser provides the functionality to parse both HTTP requests and responses.

It is ported from joyent/http-parser written in C.

§Install

Add http_parser to Cargo.toml:

[dependencies]
http_parser = "0.0.2"

§Usage

Define a callback struct:

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
}

Create an instance of HttpParser for requests:

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

Create an instance of Callback struct:

let mut cb = Callback;

Execute the parser by providing a HTTP request:

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

Structs§

Enums§

  • HttpErrno defines the encountered error during parsing.
  • HttpMethod defines supported HTTP methods.
  • HttpParserType is a type specifies whether the parser is going to parse a HTTP request, response or both.
  • ParseAction defines the potential actions that could be returned by any callback function. The parser uses it to determine consequent behavior.

Traits§

Type Aliases§