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#
pub enum ResourceKindThe type of an owned WASI HTTP handle. Only unsafe constructors accept this tag.
Fields#
FieldsOutgoingRequest#
OutgoingRequestIncomingRequest#
IncomingRequestIncomingResponse#
IncomingResponseOutgoingResponse#
OutgoingResponseIncomingBody#
IncomingBodyOutgoingBody#
OutgoingBodyFutureResponse#
FutureResponseFutureTrailers#
FutureTrailersOptions#
OptionsResponseOut#
ResponseOutResource#
pub struct ResourceAn HTTP resource owner used by provider implementations. Drop releases an untransferred handle.
Implementation Resource#
impl ResourceAssociated function take#
pub unsafe fn take(handle: u32, kind: ResourceKind) -> ResourceTakes 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#
pub fn handle(self: &Self) -> u32Borrows the owned handle. Calling this after transfer traps.
Method release#
pub unsafe fn release(self: &mut Self) -> u32Transfers 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#
impl Drop for ResourceOperation drop#
fn drop(self: &mut Self) -> ()bytesAddress#
pub fn bytesAddress(bytes: &[u8]) -> u32Returns the wasm32 address of a borrowed byte slice; the borrow must survive the host call.
textAddress#
pub fn textAddress(text: string) -> u32Returns the wasm32 address of borrowed UTF-8 text; the borrow must survive the host call.
copyBytes#
pub unsafe effect fn copyBytes(pointer: ?[*]const u8, length: u32) -> Bytes
! OutOfMemoryError ? &mut AllocatorCopies 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#
pub extern "C" struct HttpResultStorage for a canonical result<resource, error-code>. Drop frees an error's string payloads.
Implementation HttpResult#
impl HttpResultAssociated function make#
pub fn make() -> HttpResultInitializes storage before passing its address to the host.
Method handle#
pub effect fn handle(self: &Self) -> u32 ! HttpErrorReturns the handle on success, or an HTTP error retaining the WASI error ordinal.
Implementation Drop for HttpResult#
impl Drop for HttpResultOperation drop#
fn drop(self: &mut Self) -> ()FutureResult#
pub extern "C" struct FutureResultStorage for the result of an HTTP future. Drop frees error payloads in a completed result.
Implementation FutureResult#
impl FutureResultAssociated function make#
pub fn make() -> FutureResultInitializes future result storage before a host get call.
Method ready#
pub fn ready(self: &Self) -> boolWhether the future produced a value. A false result may be polled again after readiness.
Method response#
pub effect fn response(self: &Self) -> u32 ! HttpErrorReturns a completed response handle or fails with its error. Call only when ready is true.
Method trailers#
pub effect fn trailers(self: &Self) -> () ! HttpErrorChecks a completed trailers result and releases its optional owned fields handle.
protocol#
pub fn protocol(message: string<'static>) -> HttpErrorMakes a protocol failure for a malformed or unusable host result.
hostError#
pub fn hostError(code: u32) -> HttpErrorConverts a WASI HTTP error ordinal, retaining it as the provider cause.
deadline#
pub fn deadline(value: &Option<Instant>) -> Option<Instant>Copies an optional deadline without transferring the caller's option.
streamError#
pub fn streamError(error: StreamError) -> HttpErrorConverts stream failures to HTTP failure kinds.
wait#
pub unsafe effect fn wait(pollable: u32, until: &Option<Instant>) -> () ! HttpError ? &mut MonotonicClockWaits on an owned pollable and releases it, failing if the supplied clock reaches the deadline.
readBody#
pub unsafe effect fn readBody(body: Resource, maximum: usize, until: &Option<Instant>) -> Bytes
! HttpError | OutOfMemoryError ? &mut Allocator | &mut MonotonicClockDrains 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#
pub unsafe effect fn writeBody(body: Resource, bytes: &[u8], until: &Option<Instant>) -> ()
! HttpError ? &mut MonotonicClockWrites 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#
pub struct FieldOne owned HTTP field, preserving its name and raw value bytes.
Field name#
pub name: StringThe UTF-8 field name.
Field value#
pub value: BytesThe field value bytes, which need not be UTF-8.
readFields#
pub unsafe effect fn readFields(handle: u32) -> List<Field> ! HttpError | OutOfMemoryError ? &mut AllocatorCopies 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#
pub unsafe effect fn appendField(handle: u32, name: string, value: &[u8]) -> () ! HttpErrorAppends a field to a live mutable fields resource. Host header restrictions remain in force.
responseHead#
pub effect fn responseHead(status: u16, fields: &[Field]) -> OwnedResponseHead
! HttpError | OutOfMemoryError ? &mut AllocatorValidates and copies response fields and status into Silk's portable response-head value.
Category: Native platform.
Profiles: wasm32-wasip2.