2 releases

Uses old Rust 2015

0.0.2 Aug 10, 2015
0.0.1 May 1, 2015

#37 in #mut

Download history 58/week @ 2024-03-13 67/week @ 2024-03-20 43/week @ 2024-03-27 47/week @ 2024-04-03 34/week @ 2024-04-10 69/week @ 2024-04-17 101/week @ 2024-04-24 27/week @ 2024-05-01 15/week @ 2024-05-08 26/week @ 2024-05-15 68/week @ 2024-05-22 52/week @ 2024-05-29 261/week @ 2024-06-05 164/week @ 2024-06-12 69/week @ 2024-06-19 61/week @ 2024-06-26

571 downloads per month
Used in http-pull-parser

MIT license

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

No runtime deps