http_request_parser

Crates.iohttp_request_parser
lib.rshttp_request_parser
version0.2.0
sourcesrc
created_at2022-10-21 22:11:03.639276
updated_at2022-12-17 10:48:09.831073
descriptionConverts raw http request to a Request and build Response
homepage
repositoryhttps://github.com/matteac/http_parser
max_upload_size
id693962
size4,551
Mateo Acuña (matteac)

documentation

README

http_parser

Converts raw request to Request and build Responses

Parse the raw http request to Request

    for stream in listener.incoming(){
        let mut tcp_stream = stream.unwrap();
        let request = http_parser::Request::from(&tcp_stream);

And now you can use Request properties to build a Response and send it

        let request = http_request_parser::Request::from(&tcp_stream);
        let mut response = http_request_parser::Response::new();

        if request.path == "/" {
            response.body = "Hello, World!".to_owned();
        } else {
            response.headers = vec!["Content-Type: application/json".to_owned()];
            response.body = format!("{{\n\t\"actualPath\":\"{}\"\n}}", request.path);
        }
        response.send(&tcp_stream)
    }
Commit count: 8

cargo fmt