silk.http.server_wasi.
HTTP requests delivered to a WASI Preview 2 component.
When to use#
Export the canonical wasi:http/incoming-handler@0.2.12#handle function from a component
with the wasi:http/incoming-handler WIT interface. Transfer its two handles to
Exchange.take, then read the request and send one response. The host owns listening,
transport, TLS, and HTTP framing. Provide Allocator and MonotonicClock to body operations.
Details#
Request metadata is copied into owned values. Bodies are bounded by the caller's limit and deadline. A response is submitted before its body is written, so host backpressure can advance. Dropping an unanswered exchange releases both handles; the host treats it as a failed request.
Import as WasiHttpServer with import silk.http.server_wasi as WasiHttpServer.
Public declarations: 2.
Request#
pub struct RequestAn owned snapshot of request metadata. Field order, duplicates, and raw field values survive.
Field method#
pub method: StringThe case-sensitive HTTP method.
Field pathWithQuery#
pub pathWithQuery: Option<String>The path and optional query supplied by the host, absent when the request has neither.
Field scheme#
pub scheme: Option<String>The request scheme, when supplied by the host.
Field authority#
pub authority: Option<String>The request authority, when supplied by the host.
Field fields#
pub fields: List<Field>The request's fields in host order.
Exchange#
pub struct ExchangeOwns one incoming request and its response out-parameter. Responding consumes this value.
Implementation Exchange#
impl ExchangeAssociated function take#
pub unsafe fn take(request: u32, response: u32) -> ExchangeTakes the incoming-request and response-outparam handles passed to the WIT handle export.
Both handles must be live, unborrowed, and uniquely owned; the caller gives up ownership.
Method metadata#
pub effect fn metadata(self: &Self) -> Request ! HttpError | OutOfMemoryError ? &mut AllocatorCopies the request method, optional URL parts, and fields. It does not consume the body.
Method readBody#
pub effect fn readBody(self: &mut Self, maximum: usize, deadline: Option<Instant>) -> Bytes
! HttpError | OutOfMemoryError ? &mut Allocator | &mut MonotonicClockReads the request body once, enforcing the byte limit and absolute monotonic deadline. A second call fails. Dropping a failed read releases its body and stream resources.
Method respond#
pub effect fn respond(self: Self, status: u16, fields: &[Field], body: &[u8], deadline: Option<Instant>) -> ()
! HttpError ? &mut MonotonicClockSends a response with ordered fields and a complete body, consuming this exchange. The host validates status and field restrictions. Failure before submission drops the out-parameter; failure after submission terminates the response body.
Category: HTTP.
Profiles: wasm32-wasip2.