HttpMuncher: Rust Streaming HTTP parser
Rust wrapper for Joyent's http-parser library.
It's intended to be used as an HTTP/1.x protocol handler in Rust-based web servers.
Motivation
Why not write a brand new HTTP parser from scratch in Rust or just use an existing crate such as httparse?
Here's why:
- Joyent's library is based on a full-featured and robust nginx's HTTP parser, and it's safe, fast, and lightweight by design;
- It's compatible with HTTP/1.1, including upgrade connections and chunked responses;
- I haven't found a decent HTTP parser that is capable of streamed parsing, i.e. the one that can eagerly use partial data that comes from a TCP socket;
- Rust's FFI has little to no overhead;
- In most cases, it's silly to reinvent the wheel;
- It was a lot of fun trying to learn Rust along the way. :)
Usage
Add the library to your Cargo.toml
dependencies section:
[dependencies]
http-muncher = "0.2.1"
Or, for the edge version:
[dependency.http-muncher]
git = "https://github.com/nbaksalyar/rust-streaming-http-parser"
And then you can use it this way:
extern crate http_muncher;
// Include the 2 main public interfaces of the crate
use ;
// Now let's define a new listener for parser events:
;
// Now execute "cargo run", and as a result you should see this output:
// Content-Type:
// text/plain
// Content-Length:
// 0
// Hello:
// World
// ... and the rest isf almost the same - have fun experimenting!
Some more basic usage examples can be found in the library tests as well.
API documentation
You can find API docs here.
License
The MIT License (MIT)
Copyright (c) 2015 Nikita Baksalyar <nikita.baksalyar@gmail.com>