Skip to main content

Module tower

Module tower 

Source
Available on crate feature tower only.
Expand description

Tower interoperability (tower feature): adapters between rws’s own Application/Middleware and the Tower Service/Layer traits, so tonic gRPC services and tower-http layers work in an rws app, and an rws app works in a Tower stack. rws itself doesn’t run on Tower: its request path stays the native one, and nothing here is compiled without the feature.

  • TowerApp / mount — a Tower service (a tonic server, a tower-http ServeDir, an axum Router) as an rws Application.
  • TowerLayer — a Tower layer (tower-http’s SetResponseHeader, ValidateRequestHeader, Timeout, …) as rws middleware.
  • TowerService — an rws app as a Tower service, for hyper or axum.

Requests and responses cross as http::Request<Body> / http::Response<Body> (Body implements http_body::Body).

Tower futures run on one process-wide runtime, rws-tower (2 threads): tokio I/O and timers belong to the runtime that made them, and an rws handler may run under the shared runtime, a per-core one or none at all. Its threads have no trace context, so automatic client spans (crate::otel) don’t nest under requests a Tower service answers.

Structs§

Body
The http_body::Body rws hands to Tower and gets back from its own handlers: bytes in one frame, or chunks (and trailers) from a channel.
Mount
What mount returns.
Next
The rest of the rws stack, as the Tower service a layer wraps.
TowerApp
A Tower service as an rws Application: every request goes to it. mount puts one under a path prefix in front of another app.
TowerLayer
A Tower Layer — tower-http’s SetResponseHeaderLayer, ValidateRequestHeaderLayer, TimeoutLayer, NormalizePathLayer, … — as rws Middleware: app.wrap(TowerLayer::new(layer)).
TowerService
An rws Application as a Tower Service<http::Request<B>> — to serve it with hyper, or nest it in an axum Router (Router::fallback_service).

Functions§

from_http_request
An http::Request as an rws request, its body read into memory.
from_http_response
An http::Response as an rws response. A body that’s gRPC, or of unknown or large size, streams through stream_pipe (polled on rws-tower), its trailers in Response::trailers; small ones are collected.
mount
Requests whose path starts with prefix go to service, the rest to fallback.
to_http_request
An rws request as an http::Request (body as given).
to_http_response
An rws response as an http::Response: buffered bodies in one frame, files and pipes streamed (read on the rws-tower blocking pool), with Response::trailers after them.

Type Aliases§

BoxError
The error type bodies and services are converted to.