salvo
Running an Ulo application inside a salvo server with ulo-http-salvo.
ulo-http-salvo is a native embedding: the adapter implements salvo::Handler, nested under a path or as the catch-all. It builds against salvo 0.92 with the server, server-handle, http1 and http2 features. Its MSRV is 1.92, above the workspace's 1.88, so an application using it needs that toolchain.
Mounting
use salvo::prelude::*;
use ulo::App;
let server = ulo_http_salvo::Embedded::new().nested_at("/api");
let embedded = server.handle();
let app = App::builder(AppModule).runtime(ulo_runtime_tokio::Tokio::current()).wire()?.connect().await?.bind(server).listen().await?;
let router = Router::new().push(Router::with_path("api/{**rest}").goal(ulo_http_salvo::handler(&embedded)));
let acceptor = salvo::conn::TcpListener::new("0.0.0.0:8080").bind().await;
let server = Server::new(ulo_http_salvo::Closing::new(&embedded, acceptor));
ulo_http_salvo::run(app, &embedded, server, Service::new(router), ulo_runtime_tokio::shutdown_signal()).await?;(From the crate documentation of ulo-http-salvo.)
The server is built over Closing, which drops the acceptor it wraps when the drain begins. Dropping the acceptor closes its listener. salvo keeps its acceptor until every connection has closed, so without Closing a connection arriving during the drain would be taken by the kernel and never served. run's parameter type, salvo::Server<Closing<A>>, requires it. run closes the app and answers Err for a server built from another embedding's handle. The rest of the server is configured as usual: with_http_builder, http1_mut, http2_mut and fuse_factory are kept.
What it declares
- The app strips the prefix. salvo hands its handler the full path. A request outside the
nested_atprefix is answered with the app's 404 and logged atwarnonce. - The peer address from
Request::remote_addr, and WebSocket upgrades through theOnUpgradesalvo leaves in the extensions. - Host extensions are copied from
Request::extensions. A value a middleware put in theDepotcrosses through aforwardcopy overSalvoRequest, which holds the request and theDepot. - No miss forwarding and no TLS information. Bodies are streamed, and a dropped response body is observed at the disconnect.
OriginalPathis a built-in forward, read fromreq.uri().path(). The app's response,Routingincluded, goes into salvo's response extensions, where a hoop after the handler reads it.