wasmtime_wasi_http

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