pub struct FetchletService { /* private fields */ }Expand description
A cloneable Tower service for a shared fetchlet application.
It accepts http::Request<B> for any body with Bytes data and returns
http::Response<fetchlet::Body>, so it serves hyper connections and axum
routers alike. The configured public origin supplies the scheme and
authority; the incoming path, query, method, headers and body are kept. By
default the incoming body is collected within the application’s request
body budget before the handler runs; FetchletService::stream_request_bodies
passes it as a stream.
Implementations§
Source§impl FetchletService
impl FetchletService
pub fn new(app: AppHandle, public_origin: &str) -> Result<Self, Error>
Sourcepub fn client_address(
self,
address: impl Fn(&Parts) -> Option<IpAddr> + Send + Sync + 'static,
) -> Self
pub fn client_address( self, address: impl Fn(&Parts) -> Option<IpAddr> + Send + Sync + 'static, ) -> Self
Supply the client address of the default RequestContext.
Servers keep connection data in their own request extensions, such as
axum’s ConnectInfo; this callback reads it.
Sourcepub fn context<C, F>(self, context: F) -> Self
pub fn context<C, F>(self, context: F) -> Self
Supply application metadata using the incoming HTTP request parts.
It replaces the default RequestContext as the Fetch entry’s second
argument, which JavaScript reads.
Sourcepub fn trusted_context(
self,
context: impl Fn(&Parts) -> Context + Send + Sync + 'static,
) -> Self
pub fn trusted_context( self, context: impl Fn(&Parts) -> Context + Send + Sync + 'static, ) -> Self
Derive the trusted fetchlet::Context of each request in Rust.
The Context stays out of JavaScript. Host fetches of the request carry
it to in-process routes registered with
fetchlet::OriginRouter::internal, for example a router served
through service_transport. Use it for the
authenticated principal, tenant or trace data instead of request
headers that JavaScript can set. It replaces a Context that earlier
middleware put in the request extensions.
Sourcepub fn on_error(self, callback: impl Fn(&Error) + Send + Sync + 'static) -> Self
pub fn on_error(self, callback: impl Fn(&Error) + Send + Sync + 'static) -> Self
Observe detailed errors in Rust while HTTP responses use general messages.
Sourcepub fn stream_request_bodies(self) -> Self
pub fn stream_request_bodies(self) -> Self
Pass incoming bodies to the handler as a stream instead of collecting them.
The handler starts before the body has arrived and reads it as a
ReadableStream. A declared Content-Length over the request body
budget is still rejected with 413 before execution. Bytes over the
budget without a declared length, and failures of the incoming body,
reach the handler as errors of its body stream, so the handler decides
the response status.
Sourcepub async fn fetch<B>(
&self,
request: Request<B>,
) -> Result<Response<Body>, Error>
pub async fn fetch<B>( &self, request: Request<B>, ) -> Result<Response<Body>, Error>
Run the handler, returning detailed errors.
Sourcepub fn error_response(&self, error: &Error) -> Response<Body>
pub fn error_response(&self, error: &Error) -> Response<Body>
Report an error to the callback and answer with a general response.
Trait Implementations§
Source§impl Clone for FetchletService
impl Clone for FetchletService
Source§impl<B> Service<Request<B>> for FetchletService
impl<B> Service<Request<B>> for FetchletService
Source§type Future = Pin<Box<dyn Future<Output = Result<<FetchletService as Service<Request<B>>>::Response, !>> + Send>>
type Future = Pin<Box<dyn Future<Output = Result<<FetchletService as Service<Request<B>>>::Response, !>> + Send>>
Source§fn poll_ready(
&mut self,
_context: &mut Context<'_>,
) -> Poll<Result<(), Infallible>>
fn poll_ready( &mut self, _context: &mut Context<'_>, ) -> Poll<Result<(), Infallible>>
Poll::Ready(Ok(())) when the service is able to process requests. Read moreAuto Trait Implementations§
impl !Freeze for FetchletService
impl !RefUnwindSafe for FetchletService
impl !UnwindSafe for FetchletService
impl Forget for FetchletService
impl Move for FetchletService
impl Send for FetchletService
impl Sync for FetchletService
impl Unpin for FetchletService
impl UnsafeUnpin for FetchletService
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
impl<T> ParallelSend for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<S, R> ServiceExt<R> for Swhere
S: Service<R>,
impl<S, R> ServiceExt<R> for Swhere
S: Service<R>,
Source§fn into_make_service(self) -> IntoMakeService<S>
fn into_make_service(self) -> IntoMakeService<S>
MakeService, that is a Service whose
response is another service. Read moreSource§fn into_make_service_with_connect_info<C>(
self,
) -> IntoMakeServiceWithConnectInfo<S, C>
fn into_make_service_with_connect_info<C>( self, ) -> IntoMakeServiceWithConnectInfo<S, C>
MakeService, that will store C’s
associated ConnectInfo in a request extension such that ConnectInfo
can extract it. Read moreSource§fn handle_error<F, T>(self, f: F) -> HandleError<Self, F, T>
fn handle_error<F, T>(self, f: F) -> HandleError<Self, F, T>
HandleError, that will handle errors
by converting them into responses. Read moreSource§impl<T, Request> ServiceExt<Request> for T
impl<T, Request> ServiceExt<Request> for T
Source§fn ready(&mut self) -> Ready<'_, Self, Request> ⓘwhere
Self: Sized,
fn ready(&mut self) -> Ready<'_, Self, Request> ⓘwhere
Self: Sized,
Source§fn ready_oneshot(self) -> ReadyOneshot<Self, Request> ⓘwhere
Self: Sized,
fn ready_oneshot(self) -> ReadyOneshot<Self, Request> ⓘwhere
Self: Sized,
Source§fn oneshot(self, req: Request) -> Oneshot<Self, Request> ⓘwhere
Self: Sized,
fn oneshot(self, req: Request) -> Oneshot<Self, Request> ⓘwhere
Self: Sized,
Service, calling it with the provided request once it is ready.Source§fn and_then<F>(self, f: F) -> AndThen<Self, F>
fn and_then<F>(self, f: F) -> AndThen<Self, F>
poll_ready method. Read moreSource§fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
poll_ready method. Read moreSource§fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
poll_ready method. Read moreSource§fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
Result<Self::Response, Self::Error>)
to a different value, regardless of whether the future succeeds or
fails. Read more