use http::{Request, Response};
use unit_rs::{http::HttpHandler, Unit};
fn main() {
let mut unit = Unit::new().unwrap();
unit.set_request_handler(HttpHandler::new(|req: Request<Vec<u8>>| {
let body = format!("Hello world!\n\nBody length: {}\n", req.body().len());
eprintln!("Received reqest for: {}", req.uri().path());
if req.uri().path() == "/panic" {
panic!("The /panic path panics!")
}
let response = Response::builder()
.header("Content-Type", "text/plain")
.body(body.into_bytes())
.unwrap();
Ok(response)
}));
unit.run();
}