Crates.io | http_request_parser |
lib.rs | http_request_parser |
version | 0.2.0 |
source | src |
created_at | 2022-10-21 22:11:03.639276 |
updated_at | 2022-12-17 10:48:09.831073 |
description | Converts raw http request to a Request and build Response |
homepage | |
repository | https://github.com/matteac/http_parser |
max_upload_size | |
id | 693962 |
size | 4,551 |
Converts raw request to Request
and build Response
s
Request
for stream in listener.incoming(){
let mut tcp_stream = stream.unwrap();
let request = http_parser::Request::from(&tcp_stream);
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)
}