5 releases (stable)
new 2.0.1 | Mar 1, 2025 |
---|---|
1.2.0 | Feb 28, 2025 |
1.1.0 | Feb 24, 2025 |
0.1.0 | Feb 23, 2025 |
#1888 in Network programming
174 downloads per month
6KB
81 lines
lazyhttp
An easy library to handle stream objects (TcpStream, TlsStream, etc) transferring HTTP data, providing functions which return a Request from the http crate.
This library does not handle networking or responding. This is really intended to remove a snippet of code that I find myself copying and pasting over and over again.
Important: This library will also only accept bodies if they are sent with a Content-Length
header.
Example
let listener = TcpListener::bind("addr");
for stream in listener.incoming() {
let stream = stream.unwrap();
if let Ok(req) = lazyhttp::handle_stream(&stream) {
// Do something with req
}
}
Note, this is not a good example for production code. Remember proper error handling and some form of async or multithreading for a server environment.
Dependencies
~650KB
~10K SLoC