http_request_parser 0.2.0

Converts raw http request to a Request and build Response
Documentation
  • Coverage
  • 0%
    0 out of 13 items documented0 out of 0 items with examples
  • Size
  • Source code size: 4.55 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 359.72 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • matteac

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)
    }