Crate http_parser [−] [src]
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
| HttpParser |
The HTTP parser that parses requests and responses. |
| HttpVersion |
HTTP protocol version. |
Enums
| HttpErrno |
|
| HttpMethod |
|
| HttpParserType |
|
| ParseAction |
|
Traits
| HttpParserCallback |
It defines the callback functions that would be called by parser. |
Type Definitions
| CallbackResult |
Result of a callback function. |