Skip to main content

service_transport

Function service_transport 

Source
pub fn service_transport<S, B>(service: S) -> impl FetchTransport
where S: Service<Request<Body>, Response = Response<B>> + Clone + Send + Sync + 'static, S::Error: Display, S::Future: Send + 'static, B: Body<Data = Bytes> + Send + 'static, B::Error: Display,
Expand description

Serve host fetches with a Tower service, such as an axum Router.

The same service can serve public HTTP and in-process fetches from JavaScript. Requests keep their method, absolute URI, headers, body and extensions, so handlers read the trusted fetchlet::Context from the extensions when the route receives it (see fetchlet::OriginRouter::internal). In-process requests carry no connection data; handlers that need it should get it from the Context. Response bodies stream back to JavaScript. Dropping the fetch drops the service future. A service error rejects the fetch with a general transport error; its detail stays in Rust.