pub struct ProxyHandler<S: HandlerState>(/* private fields */);component-model-async only.Expand description
Represents the state of a web server.
Note that this supports optional instance reuse, enabled when
S::WorkerState::should_accept_request returns ShouldAccept::Yes more
than once for a given instance. See WorkerState for details.
Implementations§
Source§impl<S> ProxyHandler<S>where
S: HandlerState,
impl<S> ProxyHandler<S>where
S: HandlerState,
Sourcepub fn new(state: S) -> Self
pub fn new(state: S) -> Self
Create a new ProxyHandler with the specified application state and
pre-instance.
Sourcepub async fn handle(
&self,
id: <S::WorkerState as WorkerState>::RequestId,
request: Request,
) -> Result<Response, Error>
pub async fn handle( &self, id: <S::WorkerState as WorkerState>::RequestId, request: Request, ) -> Result<Response, Error>
Handle the specified request, returning a response on success or the tuple of the request and error on failure.
This function will return a wasmtime::Error on failure, which may be
downcast to a more specific type in certain scenarios:
-
InstantiationErrorif a new worker was created to handle the request but could not instantiate the guest component. -
ExpirationErrorif the request expired before it produced a response. SeeWorkerState::on_request_startfor details. -
TrapOrPanicErrorif the worker responsible for handling the request trapped or panicked before it produced a response. This may be used when a trap occurs but cannot be traced to a specific request, e.g. during concurrent request handling.
In other failure cases (e.g. wasi:http/types#error-code return values
and/or traps when executing synchronous WASIp2 handler functions), the
original error returned by the handler will be returned.
§Backpressure
Note that this API does not implement any form of backpressure to limit
the number of in-flight Requests being processed. This function
may spawn new tokio tasks, instantiate new modules under new stores, and
queue up pending Requests while waiting for previous instances. In all
of these situations invoking this function will consume some host-side
resources until the request is done.
Embedders using this API must ensure to take this into account. If an infinite number of requests can be fed into this function then it’s recommended to take a semaphore, for example, around this function call to limit the number of concurrent requests that are being processed.
Trait Implementations§
Source§impl<S: HandlerState> Clone for ProxyHandler<S>
impl<S: HandlerState> Clone for ProxyHandler<S>
Auto Trait Implementations§
impl<S> Freeze for ProxyHandler<S>
impl<S> RefUnwindSafe for ProxyHandler<S>where
S: RefUnwindSafe,
impl<S> Send for ProxyHandler<S>
impl<S> Sync for ProxyHandler<S>
impl<S> Unpin for ProxyHandler<S>
impl<S> UnsafeUnpin for ProxyHandler<S>
impl<S> UnwindSafe for ProxyHandler<S>where
S: RefUnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more