Available on crate feature
http
only.Expand description
This module contains an adapter to the Request and Response types from the
http
crate.
§Example
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());
let response = Response::builder()
.header("Content-Type", "text/plain")
.body(body.into_bytes())?;
Ok(response)
}));
unit.run();
}
Structs§
- Http
Handler - Adapter to use types from the
http
crate. - Request
- Represents an HTTP request.
- Response
- Represents an HTTP response
Traits§
- Http
Service - A trait for request handlers that uses types from the
http
crate.