Crates.io | htpp |
lib.rs | htpp |
version | 0.2.2 |
source | src |
created_at | 2024-10-17 19:21:39.513069 |
updated_at | 2024-10-23 18:04:40.872735 |
description | A simple, fast, and secure http parser. It adheres strictly to the http specification, which is intentional as to be efficient and prevent possible http related attacks. It only supports http 1.1 but support for http 2.0 is planned |
homepage | |
repository | https://github.com/Albassel/htpp |
max_upload_size | |
id | 1413541 |
size | 20,306 |
A fast and simple HTTP 1.1 parser written in Rust
To parse an HTTP request:
let req = b"GET /index.html HTTP/1.1\r\nAccept: */*\r\n\r\n";
let parsed = htpp::Request::parse(req).unwrap();
assert!(parsed.method() == htpp::Method::Get);
assert!(parsed.path() == "/index.html");
assert!(parsed.headers().len() == 1);
assert!(parsed.headers()[0].name == "Accept");
assert!(parsed.headers()[0].val == b"*/*");
To parse an HTTP response:
let res = b"HTTP/1.1 200 OK\r\nAccept: */*\r\n\r\n";
let parsed = htpp::Response::parse(res).unwrap();
assert!(parsed.status() == 200);
assert!(parsed.reason() == "OK");
assert!(parsed.headers().len() == 1);
assert!(parsed.headers()[0].name == "Accept");
assert!(parsed.headers()[0].val == b"*/*");
Feel free to make a pull request if you think you can improve the code