Expand description
§unit-rs
unit-rs
is a safe wrapper around the C libunit
library from NGINX Unit,
which allows creating Unit applications in Rust.
§Example
use unit_rs::{Unit, Request};
fn main() {
let mut unit = Unit::new().unwrap();
unit.set_request_handler(|req: Request<'_>| {
let headers = &[("Content-Type", "text/plain")];
let body = "Hello world!\n";
req.send_response(200, headers, body)?;
Ok(())
});
unit.run();
}
§Features
Currently not all features are supported, but enough are available to inspect all aspects of a request and create a response.
This library is also capable of multi-threading by creating additional
instances of Unit
.
When the http
feature enabled, the http::HttpHandler
adapter can be
used to write handlers using types from the http
crate.
§Missing features
WebSockets support is not yet implemented.
A callback for inspecting a request header (and potentially closing the request) before Unit buffers the whole request body is not yet available.
There is currently no way to perform asynchronous handling of requests. Handlers with expensive computations or blocking IO will block the whole thread context.
Modules§
Structs§
- Body
Reader - A reader that reads from the request body.
- Body
Writer - A writer that writes to a Unit shared memory response buffer.
- Request
- A request received by the NGINX Unit server.
- Response
- A buffer for constructing an initial response.
- Unit
- The Unit application context.
- Unit
Error - Error code returned by the Unit library.
- Unit
Init Error - Error code returned when Unit could not be initialized.
Traits§
- Unit
Service - A trait that can be implemented by request handlers to be used with
Unit::set_request_handler()
.
Type Aliases§
- Unit
Result - Result type returned from methods that have a
UnitError
error.