Skip to main content

ProxyHandler

Struct ProxyHandler 

Source
pub struct ProxyHandler<S: HandlerState>(/* private fields */);
Available on crate feature 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,

Source

pub fn new(state: S) -> Self

Create a new ProxyHandler with the specified application state and pre-instance.

Source

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:

  • InstantiationError if a new worker was created to handle the request but could not instantiate the guest component.

  • ExpirationError if the request expired before it produced a response. See WorkerState::on_request_start for details.

  • TrapOrPanicError if 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.

Source

pub fn state(&self) -> &S

Return a reference to the application state.

Trait Implementations§

Source§

impl<S: HandlerState> Clone for ProxyHandler<S>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> MaybeSendSync for T

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Pointee for T

§

type Pointer = u32

§

fn debug( pointer: <T as Pointee>::Pointer, f: &mut Formatter<'_>, ) -> Result<(), Error>

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more