pub trait WasiHttpHooks: Send {
Show 15 methods
// Provided methods
fn is_forbidden_header(&mut self, name: &HeaderName) -> bool { ... }
fn is_supported_scheme(&mut self, scheme: &Scheme) -> bool { ... }
fn set_host_header(&mut self) -> bool { ... }
fn default_scheme(&mut self) -> Option<Scheme> { ... }
fn send_request(
&mut self,
request: Request<WasiBody>,
options: Option<RequestOptions>,
fut: Box<dyn Future<Output = Result<(), Error>> + Send>,
) -> Box<dyn Future<Output = Result<(Response<WasiBody>, Box<dyn Future<Output = Result<(), Error>> + Send>)>> + Send> { ... }
fn p2_outgoing_body_buffer_chunks(&mut self) -> usize { ... }
fn p2_outgoing_body_chunk_size(&mut self) -> usize { ... }
fn p2_error_from_hyper(&mut self, err: &Error) -> ErrorCode { ... }
fn p2_error_from_connect(&mut self, err: &Error) -> ErrorCode { ... }
fn p2_error_from_tls(&mut self, err: &Error) -> ErrorCode { ... }
fn p2_error_from_dns(&mut self, err: &InvalidDnsNameError) -> ErrorCode { ... }
fn p3_error_from_hyper(&mut self, err: &Error) -> ErrorCode { ... }
fn p3_error_from_connect(&mut self, err: &Error) -> ErrorCode { ... }
fn p3_error_from_tls(&mut self, err: &Error) -> ErrorCode { ... }
fn p3_error_from_dns(&mut self, err: &InvalidDnsNameError) -> ErrorCode { ... }
}Expand description
A trait which provides hooks into internal WASI HTTP operations.
Note that when using this type if state is needed to implement the methods
the state will need to be stored separately in a distinct structure to
implement this trait as the same type can’t implement both WasiHttpView
and WasiHttpHooks and be usable.
§Example
use wasmtime::component::ResourceTable;
use wasmtime_wasi_http::{WasiHttpCtx, WasiHttpView, WasiHttpCtxView, WasiHttpHooks};
struct MyState {
http_ctx: WasiHttpCtx,
table: ResourceTable,
hooks: MyHooks,
}
impl MyState {
fn new() -> MyState {
MyState {
table: ResourceTable::new(),
http_ctx: WasiHttpCtx::new(),
hooks: MyHooks,
}
}
}
impl WasiHttpView for MyState {
fn http(&mut self) -> WasiHttpCtxView<'_> {
WasiHttpCtxView {
ctx: &mut self.http_ctx,
table: &mut self.table,
hooks: &mut self.hooks,
}
}
}
struct MyHooks;
impl WasiHttpHooks for MyHooks {
fn is_forbidden_header(&mut self, name: &http::HeaderName) -> bool {
*name == http::header::AUTHORIZATION ||
wasmtime_wasi_http::DEFAULT_FORBIDDEN_HEADERS.contains(name)
}
}Provided Methods§
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.
Sourcefn is_supported_scheme(&mut self, scheme: &Scheme) -> bool
fn is_supported_scheme(&mut self, scheme: &Scheme) -> bool
Whether a given scheme should be considered supported.
handle will return Error::HttpProtocolError for unsupported schemes.
Sourcefn set_host_header(&mut self) -> bool
fn set_host_header(&mut self) -> bool
Whether to set host header in the request passed to send_request.
Sourcefn default_scheme(&mut self) -> Option<Scheme>
fn default_scheme(&mut self) -> Option<Scheme>
Scheme to default to, when not set by the guest.
If None, handle will return Error::HttpProtocolError
for requests missing a scheme.
Sourcefn send_request(
&mut self,
request: Request<WasiBody>,
options: Option<RequestOptions>,
fut: Box<dyn Future<Output = Result<(), Error>> + Send>,
) -> Box<dyn Future<Output = Result<(Response<WasiBody>, Box<dyn Future<Output = Result<(), Error>> + Send>)>> + Send>
Available on crate feature default-send-request only.
fn send_request( &mut self, request: Request<WasiBody>, options: Option<RequestOptions>, fut: Box<dyn Future<Output = Result<(), Error>> + Send>, ) -> Box<dyn Future<Output = Result<(Response<WasiBody>, Box<dyn Future<Output = Result<(), Error>> + Send>)>> + Send>
default-send-request only.Send an outgoing request.
This function will be used by the wasi:http/handler#handle implementation.
The specified Future fut will be used to communicate
a response processing error, if any.
For example, if the response body is consumed via wasi:http/types.response#consume-body,
a result will be sent on fut.
The returned Future can be used to communicate
a request processing error, if any, to the constructor of the request.
For example, if the request was constructed via wasi:http/types.request#new,
a result resolved from it will be forwarded to the guest on the future handle returned.
Content-Length of the request passed to this function will be validated, however no
Content-Length validation will be performed for the received response.
Sourcefn p2_outgoing_body_buffer_chunks(&mut self) -> usize
Available on crate feature p2 only.
fn p2_outgoing_body_buffer_chunks(&mut self) -> usize
p2 only.Number of distinct write calls to the outgoing body’s output-stream that the implementation will buffer. Default: 1.
Sourcefn p2_outgoing_body_chunk_size(&mut self) -> usize
Available on crate feature p2 only.
fn p2_outgoing_body_chunk_size(&mut self) -> usize
p2 only.Maximum size allowed in a write call to the outgoing body’s output-stream. Default: 1024 * 1024.
Sourcefn p2_error_from_hyper(&mut self, err: &Error) -> ErrorCode
Available on crate feature p2 only.
fn p2_error_from_hyper(&mut self, err: &Error) -> ErrorCode
p2 only.Optional hook to configure the error code for hyper errors.
Sourcefn p2_error_from_connect(&mut self, err: &Error) -> ErrorCode
Available on crate feature p2 only.
fn p2_error_from_connect(&mut self, err: &Error) -> ErrorCode
p2 only.Optional hook to configure the error code for connect I/O errors.
Sourcefn p2_error_from_tls(&mut self, err: &Error) -> ErrorCode
Available on crate feature p2 only.
fn p2_error_from_tls(&mut self, err: &Error) -> ErrorCode
p2 only.Optional hook to configure the error code for TLS I/O errors.
Sourcefn p2_error_from_dns(&mut self, err: &InvalidDnsNameError) -> ErrorCode
Available on crate features default-send-request and p2 only.
fn p2_error_from_dns(&mut self, err: &InvalidDnsNameError) -> ErrorCode
default-send-request and p2 only.Optional hook to configure the error code for DNS errors.
Sourcefn p3_error_from_hyper(&mut self, err: &Error) -> ErrorCode
Available on crate feature p3 only.
fn p3_error_from_hyper(&mut self, err: &Error) -> ErrorCode
p3 only.Optional hook to configure the error code for hyper errors.
Sourcefn p3_error_from_connect(&mut self, err: &Error) -> ErrorCode
Available on crate feature p3 only.
fn p3_error_from_connect(&mut self, err: &Error) -> ErrorCode
p3 only.Optional hook to configure the error code for connect I/O errors.
Sourcefn p3_error_from_tls(&mut self, err: &Error) -> ErrorCode
Available on crate feature p3 only.
fn p3_error_from_tls(&mut self, err: &Error) -> ErrorCode
p3 only.Optional hook to configure the error code for TLS I/O errors.
Sourcefn p3_error_from_dns(&mut self, err: &InvalidDnsNameError) -> ErrorCode
Available on crate features default-send-request and p3 only.
fn p3_error_from_dns(&mut self, err: &InvalidDnsNameError) -> ErrorCode
default-send-request and p3 only.Optional hook to configure the error code for DNS errors.
Trait Implementations§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".