Trait unit_rs::HttpService
source · [−]pub trait HttpService {
fn handle_request(
&mut self,
_req: Request<Vec<u8>>
) -> UnitResult<Response<Vec<u8>>>;
}Available on crate feature
http only.Expand description
A request handler that uses types from the http crate.
Request handles with this trait can be used with the HttpMiddleware
adapter.
Example
let mut unit = Unit::new().unwrap();
unit.set_request_handler(HttpMiddleware::new(|req: http::Request<Vec<u8>>| {
let body = format!("Hello world!\n\nBody length: {}\n", req.body().len());
let response = http::Response::builder()
.header("Content-Type", "text/plain")
.body(body.into_bytes())
.unwrap();
Ok(response)
}));