Browse the docs

silk.platform.wasi.http.

Ownership and canonical ABI operations for WASI Preview 2 HTTP providers.

When to use#

Provider implementations use these operations to release HTTP resources and host-allocated values on every exit path. Applications use silk.http.client_wasi and silk.http.server_wasi.

Import as wasi_http with import silk.platform.wasi.http as wasi_http.

Public declarations: 18.

ResourceKind#

silk
pub enum ResourceKind

The type of an owned WASI HTTP handle. Only unsafe constructors accept this tag.

Fields#

silk
Fields

OutgoingRequest#

silk
OutgoingRequest

IncomingRequest#

silk
IncomingRequest

IncomingResponse#

silk
IncomingResponse

OutgoingResponse#

silk
OutgoingResponse

IncomingBody#

silk
IncomingBody

OutgoingBody#

silk
OutgoingBody

FutureResponse#

silk
FutureResponse

FutureTrailers#

silk
FutureTrailers

Options#

silk
Options

ResponseOut#

silk
ResponseOut

Resource#

silk
pub struct Resource

An HTTP resource owner used by provider implementations. Drop releases an untransferred handle.

Implementation Resource#

silk
impl Resource

Associated function take#

silk
pub unsafe fn take(handle: u32, kind: ResourceKind) -> Resource

Takes a live handle of kind. The caller surrenders its previous owner and keeps any parent alive until this owner is dropped or transferred.

Method handle#

silk
pub fn handle(self: &Self) -> u32

Borrows the owned handle. Calling this after transfer traps.

Method release#

silk
pub unsafe fn release(self: &mut Self) -> u32

Transfers the handle without dropping it. The caller must give it to an owning host argument or another owner, and must first release all child resources.

Implementation Drop for Resource#

silk
impl Drop for Resource

Operation drop#

silk
fn drop(self: &mut Self) -> ()

bytesAddress#

silk
pub fn bytesAddress(bytes: &[u8]) -> u32

Returns the wasm32 address of a borrowed byte slice; the borrow must survive the host call.

textAddress#

silk
pub fn textAddress(text: string) -> u32

Returns the wasm32 address of borrowed UTF-8 text; the borrow must survive the host call.

copyBytes#

silk
pub unsafe effect fn copyBytes(pointer: ?[*]const u8, length: u32) -> Bytes
    ! OutOfMemoryError ? &mut Allocator

Copies an initialized host-owned buffer without taking ownership of it. The caller guarantees length readable bytes and keeps the allocation alive during the copy.

HttpResult#

silk
pub extern "C" struct HttpResult

Storage for a canonical result<resource, error-code>. Drop frees an error's string payloads.

Implementation HttpResult#

silk
impl HttpResult

Associated function make#

silk
pub fn make() -> HttpResult

Initializes storage before passing its address to the host.

Method handle#

silk
pub effect fn handle(self: &Self) -> u32 ! HttpError

Returns the handle on success, or an HTTP error retaining the WASI error ordinal.

Implementation Drop for HttpResult#

silk
impl Drop for HttpResult

Operation drop#

silk
fn drop(self: &mut Self) -> ()

FutureResult#

silk
pub extern "C" struct FutureResult

Storage for the result of an HTTP future. Drop frees error payloads in a completed result.

Implementation FutureResult#

silk
impl FutureResult

Associated function make#

silk
pub fn make() -> FutureResult

Initializes future result storage before a host get call.

Method ready#

silk
pub fn ready(self: &Self) -> bool

Whether the future produced a value. A false result may be polled again after readiness.

Method response#

silk
pub effect fn response(self: &Self) -> u32 ! HttpError

Returns a completed response handle or fails with its error. Call only when ready is true.

Method trailers#

silk
pub effect fn trailers(self: &Self) -> () ! HttpError

Checks a completed trailers result and releases its optional owned fields handle.

protocol#

silk
pub fn protocol(message: string<'static>) -> HttpError

Makes a protocol failure for a malformed or unusable host result.

hostError#

silk
pub fn hostError(code: u32) -> HttpError

Converts a WASI HTTP error ordinal, retaining it as the provider cause.

deadline#

silk
pub fn deadline(value: &Option<Instant>) -> Option<Instant>

Copies an optional deadline without transferring the caller's option.

streamError#

silk
pub fn streamError(error: StreamError) -> HttpError

Converts stream failures to HTTP failure kinds.

wait#

silk
pub unsafe effect fn wait(pollable: u32, until: &Option<Instant>) -> () ! HttpError ? &mut MonotonicClock

Waits on an owned pollable and releases it, failing if the supplied clock reaches the deadline.

readBody#

silk
pub unsafe effect fn readBody(body: Resource, maximum: usize, until: &Option<Instant>) -> Bytes
    ! HttpError | OutOfMemoryError ? &mut Allocator | &mut MonotonicClock

Drains an owned incoming body, validates completion and trailers, and enforces maximum bytes. The body must be an incoming-body handle with no existing stream child.

writeBody#

silk
pub unsafe effect fn writeBody(body: Resource, bytes: &[u8], until: &Option<Instant>) -> ()
    ! HttpError ? &mut MonotonicClock

Writes all bytes and finishes an owned outgoing body. The request or response must already have been sent to the host so that it can consume bytes under backpressure.

Field#

silk
pub struct Field

One owned HTTP field, preserving its name and raw value bytes.

Field name#

silk
pub name: String

The UTF-8 field name.

Field value#

silk
pub value: Bytes

The field value bytes, which need not be UTF-8.

readFields#

silk
pub unsafe effect fn readFields(handle: u32) -> List<Field> ! HttpError | OutOfMemoryError ? &mut Allocator

Copies a live fields resource into ordinary owned values, preserving repeated fields and order. The caller keeps the fields resource and its parent alive until the operation returns.

appendField#

silk
pub unsafe effect fn appendField(handle: u32, name: string, value: &[u8]) -> () ! HttpError

Appends a field to a live mutable fields resource. Host header restrictions remain in force.

responseHead#

silk
pub effect fn responseHead(status: u16, fields: &[Field]) -> OwnedResponseHead
    ! HttpError | OutOfMemoryError ? &mut Allocator

Validates and copies response fields and status into Silk's portable response-head value.

Category: Native platform.

Profiles: wasm32-wasip2.

View the source of this page