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§
- Http
Parser - The HTTP parser that parses requests and responses.
- Http
Version - HTTP protocol version.
Enums§
- Http
Errno HttpErrnodefines the encountered error during parsing.- Http
Method HttpMethoddefines supported HTTP methods.- Http
Parser Type HttpParserTypeis a type specifies whether the parser is going to parse a HTTP request, response or both.- Parse
Action ParseActiondefines the potential actions that could be returned by any callback function. The parser uses it to determine consequent behavior.
Traits§
- Http
Parser Callback - It defines the callback functions that would be called by parser.
Type Aliases§
- Callback
Result - Result of a callback function.