5 releases
0.2.0 | Dec 17, 2022 |
---|---|
0.1.3 | Oct 26, 2022 |
0.1.2 | Oct 26, 2022 |
0.1.1 | Oct 21, 2022 |
0.1.0 | Oct 21, 2022 |
#25 in #http-parser
5KB
77 lines
http_parser
Converts raw request to Request
and build Response
s
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)
}