Crates.io | simple_http_parser |
lib.rs | simple_http_parser |
version | 0.3.5 |
source | src |
created_at | 2022-12-17 16:21:36.518688 |
updated_at | 2023-07-06 23:33:26.584033 |
description | Converts raw http request to a Request and build Response |
homepage | |
repository | https://github.com/matteac/http_parser |
max_upload_size | |
id | 739939 |
size | 14,223 |
Converts raw request to Request
Request
let listener = TcpListener::bind("0.0.0.0:7878").unwrap();
for stream in listener.incoming() {
let mut tcp_stream = stream.unwrap();
let mut buffer = [0; 16384];
tcp_stream.read(&mut buffer).unwrap();
let raw_request = String::from_utf8_lossy(&buffer);
match Request::from(&raw_request) {
Ok(_) => {
tcp_stream
.write_all(
b"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<h1>Hello World</h1>",
)
.unwrap();
}
Err(e) => {
println!("{:?}", e);
}
}
}