Expand description
§alux-http-hyper
alux-http-hyper serves an alux-http surface over
hyper, with no web framework.
alux-http-direct answers a request with values but carries no
transport. This crate connects it to hyper: it reads a hyper request into a DirectRequest, passes
it to the surface, and writes the answer back as a hyper response.
use alux_http::HttpProgramExt;
use alux_http_direct::DirectHandlerImpl;
use alux_http_hyper::HyperRoute;
use hyper_util::rt::{TokioExecutor, TokioIo};
use hyper_util::server::conn::auto::Builder;
let api = DirectHandlerImpl::new(App::new());
let served = HyperRoute::new(api.compile_http(api.status_api::<App>()));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
loop {
let (stream, _) = listener.accept().await?;
let served = served.clone();
tokio::spawn(async move {
let connection = Builder::new(TokioExecutor::new());
let _ = connection.serve_connection(TokioIo::new(stream), served).await;
});
}The crate states a hyper::service::Service and stops there. Which runtime listens, and how
connections are driven, stays yours, so this names no runtime: tokio and hyper-util above are
the caller’s choice, not this crate’s dependencies.
A body the surface produces over time is served as one, so .stream() reaches a caller a chunk at a
time rather than being collected first.
Two kinds of request cannot reach a handler at all, and both get a response instead of killing the
connection. HttpMethod names nine methods, so a request using anything else, such as the
WebDAV PROPFIND, is answered 405 Method Not Allowed.
A request whose body cannot be read to the end is
answered 400 Bad Request.
Serves an alux-http surface over hyper, with no web framework.
alux-http-direct answers a request with values and carries
no transport, so something has to move the bytes. This is that something, and nothing more: it
reads a hyper request into a DirectRequest, hands it to the surface, and writes the answer back
as a hyper response.
It also states the accepting itself, in HyperConnections. A framework that hands out a
service rather than a loop needs nothing more than that to serve, so the interpreters for those
frameworks accept through this one rather than each writing the same loop.
Structs§
- Hyper
Connections - Accepts at one address and serves each connection with one service.
- Hyper
Route - Serves one compiled surface over hyper.
- Hyper
Server - Serves a direct HTTP surface over hyper at the address its setup names.
Constants§
- DRAIN
- The drain to serve with where a caller states none of its own.
Type Aliases§
- Connections
Error - Carries an error returned while serving connections.
- Hyper
Answer - The answer this service produces, which is a hyper response like any other.
- Hyper
Body - The body a served answer carries, whether its bytes were in hand or are still to come.