actix-web
Running an Ulo application inside an actix-web server with ulo-http-actix.
ulo-http-actix is a native embedding: the adapter implements HttpServiceFactory, and the app mounts as a scope or the default service. The app's pipeline runs inside actix's single-threaded workers, so actix's per-core runtime model is kept.
Mounting
use ulo::App;
let server = ulo_http_actix::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 host = {
let embedded = embedded.clone();
actix_web::HttpServer::new(move || actix_web::App::new().service(ulo_http_actix::scope("/api", &embedded)))
.bind(("0.0.0.0", 8080))?
};
ulo_http_actix::run(app, &embedded, host, ulo_runtime_tokio::shutdown_signal()).await?;(From the crate documentation of ulo-http-actix.)
run disables actix's own signal handling, sets shutdown_timeout to the app's drain window rounded up to the second, and stops the server with stop(true) when the app drains. It must be called inside a tokio runtime. scope("", &embedded) mounts the app as the default service.
What it declares
- No WebSocket upgrades. A gateway on the HTTP port is refused at
listen. A gateway declaredport = ownis served byulo-ws-hyper, which works beside any host. - The app strips the prefix.
web::scopeleaves the path whole. The adapter declareswithout_strips_prefix, and the app removes thenested_atprefix. - No host extensions. A value in actix's request store reaches the app only through a
forwardcopy overHttpRequest. - No miss forwarding and no TLS information.
- Request payload pumped through a channel. actix's payload is not
Sendand the app's body is, so a worker-local task pumps it through a bounded channel. - No close signal for a call in progress. actix-http keeps running a call whose connection the peer closed, or whose HTTP/2 stream it reset, until the call answers. A handler gets no signal of it beyond a request body still arriving ending with an error. The adapter declares
without_pending_closeandwithout_pending_reset. - A dropped response body is observed at the next failed write, so an idle stream is not cancelled until it has something to send.
OriginalPathis a built-in forward, read fromreq.path(). Of the app's response extensions, onlyRoutingis copied into actix's own store.
Drain
- A request whose head is still arriving gets a closed connection rather than the app's 503. From actix-web 4.15 actix's graceful stop reaches every HTTP/1 connection, and one with no complete request in progress closes at once. A request pipelined behind one in flight is dropped the same way.
- HTTP/2 is
DrainHttp2::Reset. The adapter builds actix-web without itshttp2feature, so on its own it serves HTTP/1.1. Cargo unifies features: any crate in the application that enables actix-web'shttp2turns it on here, and a server listening withlisten_auto_h2cor over TLS with ALPN then serves HTTP/2. actix sends such a connection no GOAWAY. It stays open untilshutdown_timeoutresets it, and the draining app answers its requests 503. The app'sclosetakes the whole window while one is open.
The conformance-http2 feature exists for the conformance suite only. An application serving HTTP/2 enables actix-web's http2 itself.