6 releases (3 stable)

✓ Uses Rust 2018 edition

1.2.0 May 13, 2020
1.1.0 Dec 4, 2019
1.0.0 Nov 15, 2019
0.2.0 Nov 8, 2019
0.1.1 Nov 7, 2019

#98 in #http

Download history 6/week @ 2020-02-08 46/week @ 2020-02-15 27/week @ 2020-02-22 10/week @ 2020-03-07 5/week @ 2020-03-14 25/week @ 2020-03-21 11/week @ 2020-04-04 30/week @ 2020-04-11 1/week @ 2020-04-25 33/week @ 2020-05-02 25/week @ 2020-05-09

66 downloads per month

MIT license

21KB
488 lines

Elaine

ci.img docs.img crates.img

This crate provides a lightweight and potentially incomplete http head parser implementation for async-std readers.

Goals & Stuff

This crate is intended to provide an HTTP head parser for async readers with a focus on simplicity and safety; while performance is appreciated, safety and simplicity take priority.

On Safety

The api provided by this crate will never include unsafe code directly, including code that would otherwise improve the performance of the libary. In addition, the main export - recognize - provides the guarantee that it will never over-read bytes from a reader, again at the potential loss of performance.

On Simplictity

This crate does not include the http crate in it's dependencies; though well-maintained and useful as it is, it would introduce a super set of functionality that is not required for this implementation. This decision is not in any way meant to discourage other developers from using that library.

Example

use std::boxed::Box;
use std::error::Error;

use elaine::{recognize, RequestMethod};
use async_std::task::block_on;

fn main() -> Result<(), Box<dyn Error>> {
  block_on(async {
    let mut req: &[u8] = b"GET /elaine HTTP/1.1\r\nContent-Length: 3\r\n\r\nhey";
    let result = recognize(&mut req).await.unwrap();
    assert_eq!(result.method(), Some(RequestMethod::GET));
    assert_eq!(result.len(), Some(3));
    assert_eq!(std::str::from_utf8(req), Ok("hey"));
  });
  Ok(())
}
elaine
elaine

Contributing

See CONTRIBUTING.

Dependencies

~1MB
~19K SLoC