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§
Sourcefn ctx(&mut self) -> &mut WasiHttpCtx
fn ctx(&mut self) -> &mut WasiHttpCtx
Returns a mutable reference to the WASI HTTP context.
Sourcefn table(&mut self) -> &mut ResourceTable
fn table(&mut self) -> &mut ResourceTable
Returns a mutable reference to the WASI HTTP resource table.
Provided Methods§
Sourcefn new_incoming_request<B>(
&mut self,
scheme: Scheme,
req: Request<B>,
) -> Result<Resource<HostIncomingRequest>>
fn new_incoming_request<B>( &mut self, scheme: Scheme, req: Request<B>, ) -> Result<Resource<HostIncomingRequest>>
Create a new incoming request resource.
Sourcefn new_response_outparam(
&mut self,
result: Sender<Result<Response<HyperOutgoingBody>, ErrorCode>>,
) -> Result<Resource<HostResponseOutparam>>
fn new_response_outparam( &mut self, result: Sender<Result<Response<HyperOutgoingBody>, ErrorCode>>, ) -> Result<Resource<HostResponseOutparam>>
Create a new outgoing response resource.
Sourcefn send_request(
&mut self,
request: Request<HyperOutgoingBody>,
config: OutgoingRequestConfig,
) -> HttpResult<HostFutureIncomingResponse>
fn send_request( &mut self, request: Request<HyperOutgoingBody>, config: OutgoingRequestConfig, ) -> HttpResult<HostFutureIncomingResponse>
Send an outgoing request.
Sourcefn is_forbidden_header(&mut self, _name: &HeaderName) -> bool
fn is_forbidden_header(&mut self, _name: &HeaderName) -> bool
Whether a given header should be considered forbidden and not allowed.