#http-parser #request #request-http-parser

request-http-parser

A simple library for parsing http request string to a model

2 releases

Uses new Rust 2024

new 0.1.1 Apr 28, 2025
0.1.0 Apr 28, 2025

#14 in #http-parser

Download history 179/week @ 2025-04-23

179 downloads per month

MIT license

7KB
93 lines

How to use

let mut buffer = [0; 1024];
let size =  stream.read(&mut buffer).expect("");
let req_str = String::from_utf8_lossy(&buffer[..size]);
let req = Request::new(&req_str);

Examples

    use request_http_parser::parser::{Method,Request};
    let req_str = format!(
                "POST /login HTTP/1.1\r\n\
                Content-Type: application/json\r\n\
                User-Agent: Test\r\n\
                Content-Length: {}\r\n\\r\n\
                {{\"username\": \"{}\",\"password\": \"{}\"}}",
                44, "crisandolin", "rumahorbo");
                let req = Request::new(&req_str);

    assert_eq!(Method::POST, req.method);
    assert_eq!("/login", req.path);

Dependencies

~140KB