2 releases
Uses old Rust 2015
0.0.2 | Aug 10, 2015 |
---|---|
0.0.1 | May 1, 2015 |
#37 in #mut
571 downloads per month
Used in http-pull-parser
85KB
2K
SLoC
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.
Usage
Please refer to the documentation.
Status
The parser is ported as well as unit tests. For the moment, all the test cases are passed. Besides that, I didn't do other tests around it and it was not used by other project either. So it is ready to be played around but far away to be used in production. Also, the API is unstable and may be changed.
lib.rs
:
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());