Crates.io | elaine |
lib.rs | elaine |
version | 1.2.0 |
source | src |
created_at | 2019-11-07 07:26:52.127112 |
updated_at | 2020-05-13 17:44:10.593183 |
description | Async http head reader |
homepage | https://github.com/sizethree/elaine |
repository | https://github.com/sizethree/elaine.git |
max_upload_size | |
id | 178939 |
size | 54,123 |
This crate provides a lightweight and potentially incomplete http head parser implementation for async-std readers.
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.
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.
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.
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 |
---|
See CONTRIBUTING.