HTTP Servers
rocket
Running an Ulo application inside a rocket server with ulo-http-rocket.
ulo-http-rocket is a native embedding: one catch-all rocket::route::Handler per method, mounted at a path. It builds against rocket 0.5 with the http2 feature. rocket 0.5 is on http 0.2, so the adapter converts at its edge.
Mounting
use ulo::App;
let server = ulo_http_rocket::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 rocket = rocket::build().mount("/api", ulo_http_rocket::routes(&embedded));
ulo_http_rocket::run(app, &embedded, rocket, ulo_runtime_tokio::shutdown_signal()).await?;(From the crate documentation of ulo-http-rocket.)
run sets shutdown.ctrlc = false, no shutdown signals, and shutdown.grace to the app's drain window rounded up to the second. A rocket that fails to ignite makes the app shut down naming the error.
What it declares
- The app strips the prefix.
mountleaves the URI whole. - Miss forwarding.
Embedded::on_miss(Miss::Forward)hands a request the app has no route for back to rocket with its unreadData. This is the only host that supports it. - Request bodies are buffered. rocket's
Datamust be read inside the handler, so the body is buffered under the embedding'smax_body(2 MiB unset) once the app first reads it. A larger one is answered with the same 413 as elsewhere. A body the app never reads stays unread, which is what lets a forwarded miss go back to rocket intact. - No host extensions (use
forwardoverrocket::Request) and no TLS information. - No close signal for a call in progress. rocket runs each request's handler in a task a closed connection or reset stream does not end. 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.
Routingis stored in the request's local cache as anOption<Routing>, where a fairing'son_responsereads it withreq.local_cache(|| None::<Routing>).Nonemeans the app did not answer.OriginalPathis a built-in forward, read fromreq.uri().path().
Limits
- Drain window. Once hyper's server has finished, rocket's launch waits out its whole
shutdown.graceif anything still holds the server, and a response the client abandoned during the drain leaves it waiting. A client that leaves mid-response during shutdown therefore makes the app'sclosetake the whole drain window and no longer. - WebSocket requires HTTP/1.1 (RFC 6455 §4.2.1), and rocket 0.5 keeps no request's protocol version. The adapter hands the app every request as HTTP/1.1, so a gateway on the HTTP port answers an HTTP/1.0 upgrade request with 101, where every other host answers 400. A version-dependent rule in the app, such as HTTP/1.0 closing the connection by default, reads HTTP/1.1 here too.