#http #parser

http_parser

Http request/response parser for rust

2 releases

Uses old Rust 2015

0.0.2 Aug 10, 2015
0.0.1 May 1, 2015

#2932 in Rust patterns

Download history 67/week @ 2023-10-23 24/week @ 2023-10-30 19/week @ 2023-11-06 72/week @ 2023-11-13 44/week @ 2023-11-20 81/week @ 2023-11-27 45/week @ 2023-12-04 54/week @ 2023-12-11 88/week @ 2023-12-18 35/week @ 2023-12-25 35/week @ 2024-01-01 76/week @ 2024-01-08 65/week @ 2024-01-15 74/week @ 2024-01-22 22/week @ 2024-01-29 74/week @ 2024-02-05

238 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