Skip to main content

WasiHttpHooks

Trait WasiHttpHooks 

Source
pub trait WasiHttpHooks: Send {
    // Provided methods
    fn send_request(
        &mut self,
        request: Request<HyperOutgoingBody>,
        config: OutgoingRequestConfig,
    ) -> HttpResult<HostFutureIncomingResponse> { ... }
    fn is_forbidden_header(&mut self, name: &HeaderName) -> bool { ... }
    fn outgoing_body_buffer_chunks(&mut self) -> usize { ... }
    fn outgoing_body_chunk_size(&mut self) -> usize { ... }
}
Available on crate feature p2 only.
Expand description

A trait which provides hooks into internal WASI HTTP operations.

§Example

use wasmtime::component::ResourceTable;
use wasmtime_wasi::{WasiCtx, WasiCtxView, WasiView};
use wasmtime_wasi_http::WasiHttpCtx;
use wasmtime_wasi_http::p2::{WasiHttpView, WasiHttpCtxView};

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

impl WasiHttpView for MyState {
    fn http(&mut self) -> WasiHttpCtxView<'_> {
        WasiHttpCtxView {
            ctx: &mut self.http_ctx,
            table: &mut self.table,
            hooks: Default::default(),
        }
    }
}

impl WasiView for MyState {
    fn ctx(&mut self) -> WasiCtxView<'_> {
        WasiCtxView { ctx: &mut self.ctx, table: &mut self.table }
    }
}

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

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

Provided Methods§

Source

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

Available on crate feature default-send-request only.

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.

Source

fn outgoing_body_buffer_chunks(&mut self) -> usize

Number of distinct write calls to the outgoing body’s output-stream that the implementation will buffer. Default: 1.

Source

fn outgoing_body_chunk_size(&mut self) -> usize

Maximum size allowed in a write call to the outgoing body’s output-stream. Default: 1024 * 1024.

Trait Implementations§

Source§

impl<'a> Default for &'a mut dyn WasiHttpHooks

Available on crate feature default-send-request only.
Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Implementors§