Trait wasmtime_wasi_http::types::WasiHttpView

source ·
pub trait WasiHttpView: Send {
    // Required methods
    fn ctx(&mut self) -> &mut WasiHttpCtx;
    fn table(&mut self) -> &mut ResourceTable;

    // Provided methods
    fn new_incoming_request<B>(
        &mut self,
        scheme: Scheme,
        req: Request<B>,
    ) -> Result<Resource<HostIncomingRequest>>
       where B: Body<Data = Bytes, Error = Error> + Send + Sync + 'static,
             Self: Sized { ... }
    fn new_response_outparam(
        &mut self,
        result: Sender<Result<Response<HyperOutgoingBody>, ErrorCode>>,
    ) -> Result<Resource<HostResponseOutparam>> { ... }
    fn send_request(
        &mut self,
        request: Request<HyperOutgoingBody>,
        config: OutgoingRequestConfig,
    ) -> HttpResult<HostFutureIncomingResponse> { ... }
    fn is_forbidden_header(&mut self, _name: &HeaderName) -> bool { ... }
}
Expand description

A trait which provides internal WASI HTTP state.

§Example

use wasmtime::component::ResourceTable;
use wasmtime_wasi::{WasiCtx, WasiView, WasiCtxBuilder};
use wasmtime_wasi_http::{WasiHttpCtx, WasiHttpView};

struct MyState {
    ctx: WasiCtx,
    http_ctx: WasiHttpCtx,
    table: ResourceTable,
}

impl WasiHttpView for MyState {
    fn ctx(&mut self) -> &mut WasiHttpCtx { &mut self.http_ctx }
    fn table(&mut self) -> &mut ResourceTable { &mut self.table }
}

impl WasiView for MyState {
    fn ctx(&mut self) -> &mut WasiCtx { &mut self.ctx }
    fn table(&mut self) -> &mut ResourceTable { &mut self.table }
}

impl MyState {
    fn new() -> MyState {
        let mut wasi = WasiCtxBuilder::new();
        wasi.arg("./foo.wasm");
        wasi.arg("--help");
        wasi.env("FOO", "bar");

        MyState {
            ctx: wasi.build(),
            table: ResourceTable::new(),
            http_ctx: WasiHttpCtx::new(),
        }
    }
}

Required Methods§

source

fn ctx(&mut self) -> &mut WasiHttpCtx

Returns a mutable reference to the WASI HTTP context.

source

fn table(&mut self) -> &mut ResourceTable

Returns a mutable reference to the WASI HTTP resource table.

Provided Methods§

source

fn new_incoming_request<B>( &mut self, scheme: Scheme, req: Request<B>, ) -> Result<Resource<HostIncomingRequest>>
where B: Body<Data = Bytes, Error = Error> + Send + Sync + 'static, Self: Sized,

Create a new incoming request resource.

source

fn new_response_outparam( &mut self, result: Sender<Result<Response<HyperOutgoingBody>, ErrorCode>>, ) -> Result<Resource<HostResponseOutparam>>

Create a new outgoing response resource.

source

fn send_request( &mut self, request: Request<HyperOutgoingBody>, config: OutgoingRequestConfig, ) -> HttpResult<HostFutureIncomingResponse>

Send an outgoing request.

source

fn is_forbidden_header(&mut self, _name: &HeaderName) -> bool

Whether a given header should be considered forbidden and not allowed.

Implementations on Foreign Types§

source§

impl<T: ?Sized + WasiHttpView> WasiHttpView for &mut T

source§

impl<T: ?Sized + WasiHttpView> WasiHttpView for Box<T>

Implementors§