ciallo-wasi

    WASI Preview 2 (wasi:http/incoming-handler@0.2.0) adapter bridging unmbt/ciallo Apps to Wasmtime, Spin, and WASI HTTP hosts

    wasi
    wasi-http
    wasm
    component-model
    serverless
    ciallo
    Download zip
    Author
    Version
    0.3.0
    License
    MIT
    Last updated
    5 hours ago
    Downloads
    15

    #unmbt/ciallo-wasi

    WASI Preview 2 (wasi:http/incoming-handler@0.2.0) adapter for unmbt/ciallo, bridging Wasmtime / Fermyon Spin / WASI HTTP components to unmbt/webstd and @core.App.

    WasiStreamHost

    pub(open) trait WasiStreamHost {
    fn request_method(Self, req : WasiHandle) -> WasiMethod raise WasiErrorCode
    fn request_scheme(Self, req : WasiHandle) -> WasiScheme raise WasiErrorCode
    fn request_authority(Self, req : WasiHandle) -> String raise WasiErrorCode
    fn request_path_with_query(Self, req : WasiHandle) -> String raise WasiErrorCode
    fn request_headers(Self, req : WasiHandle) -> WasiFields raise WasiErrorCode
    fn request_consume_body(Self, req : WasiHandle) -> WasiHandle raise WasiErrorCode
    fn incoming_body_stream(Self, body : WasiHandle) -> WasiHandle raise WasiErrorCode
    fn input_stream_blocking_read(Self, stream : WasiHandle, max_len : Int64) -> WasiStreamRead raise WasiErrorCode
    fn drop_input_stream(Self, stream : WasiHandle) -> Unit
    fn incoming_body_finish(Self, body : WasiHandle) -> Unit
    fn new_outgoing_response(Self, status : Int, headers : WasiFields) -> WasiHandle raise WasiErrorCode
    fn outgoing_response_body(Self, resp : WasiHandle) -> WasiHandle raise WasiErrorCode
    fn response_outparam_set_ok(Self, outparam : WasiHandle, resp : WasiHandle) -> Unit
    fn response_outparam_set_err(Self, outparam : WasiHandle, err : WasiErrorCode) -> Unit
    fn outgoing_body_write(Self, body : WasiHandle) -> WasiHandle raise WasiErrorCode
    fn output_stream_check_write(Self, stream : WasiHandle) -> Int64 raise WasiErrorCode
    fn output_stream_blocking_write_and_flush(Self, stream : WasiHandle, chunk : BytesView) -> Unit raise WasiErrorCode
    fn output_stream_subscribe(Self, stream : WasiHandle) -> WasiHandle
    fn pollable_block(Self, pollable : WasiHandle) -> Unit
    fn drop_pollable(Self, pollable : WasiHandle) -> Unit
    fn drop_output_stream(Self, stream : WasiHandle) -> Unit
    fn outgoing_body_finish(Self, body : WasiHandle) -> Unit raise WasiErrorCode
    }

    Canonical ABI host operations for wasi:http/types@0.2.0, wasi:io/streams@0.2.0, and wasi:io/poll@0.2.0. Production Wasmtime/Spin components wire this to host imports; unit tests can run against MockWasiStreamHost across native, js, and wasm targets.

    WasiErrorCode

    pub(all) suberror WasiErrorCode {
    HttpRequestUriInvalid
    HttpProtocolError
    InternalError(String)
    } derive(Eq,
    Debug
    )

    WASI Preview 2 wasi:http/types@0.2.0 error codes.

    WasiFields

    pub struct WasiFields {
    entries : Array[(String, Bytes)]
    } derive(Eq,
    Debug
    )

    WASI Preview 2 fields representation (multi-value (name, bytes) pairs).

    WasiFields::WasiFields

    fn WasiFields::WasiFields(entries? : Array[(String, Bytes)]) -> WasiFields

    WasiFields::append

    fn WasiFields::append(self : WasiFields, name : StringView, value : Bytes) -> Unit

    WasiFields::append_str

    fn WasiFields::append_str(self : WasiFields, name : StringView, value : StringView) -> Unit

    WasiFields::entries

    fn WasiFields::entries(self : WasiFields) -> Array[(String, Bytes)]

    WasiFields::get_all

    fn WasiFields::get_all(self : WasiFields, name : StringView) -> Array[Bytes]

    WasiHandle

    pub(all) struct WasiHandle(Int) derive(Eq, Hash,
    Debug
    )

    Opaque WASI Preview 2 resource handle (u32 / Int32 in Canonical ABI).

    WasiIncomingHandler

    pub struct WasiIncomingHandler {
    app :
    App

    env :
    Env

    }

    Implements the wasi:http/incoming-handler@0.2.0 handle(request, response-out) contract.

    WasiIncomingHandler::WasiIncomingHandler

    WasiIncomingHandler::handle

    async fn WasiIncomingHandler::handle(self : WasiIncomingHandler, request : WasiIncomingRequest, response_out : WasiResponseOutparam) -> Unit

    WasiIncomingRequest

    pub struct WasiIncomingRequest {
    meth : WasiMethod
    scheme : WasiScheme
    authority : String
    path_with_query : String
    headers : WasiFields
    body_chunks : Array[Bytes]
    }

    WASI Preview 2 incoming-request model.

    WasiIncomingRequest::WasiIncomingRequest

    fn WasiIncomingRequest::WasiIncomingRequest(meth? : WasiMethod, scheme? : WasiScheme, authority? : String, path_with_query? : String, headers? : WasiFields, body_chunks? : Array[Bytes]) -> WasiIncomingRequest

    WasiMethod

    pub(all) enum WasiMethod {
    Get
    Head
    Post
    Put
    Delete
    Connect
    Options
    Trace
    Patch
    Other(String)
    } derive(Eq,
    Debug
    )

    WASI Preview 2 wasi:http/types@0.2.0 HTTP method.

    WasiOutgoingResponse

    pub struct WasiOutgoingResponse {
    status_code : Int
    headers : WasiFields
    body_chunks : Array[Bytes]
    } derive(Eq,
    Debug
    )

    WASI Preview 2 outgoing-response model.

    WasiOutgoingResponse::body_bytes

    fn WasiOutgoingResponse::body_bytes(self : WasiOutgoingResponse) -> Bytes

    WasiOutgoingResponse::body_text

    fn WasiOutgoingResponse::body_text(self : WasiOutgoingResponse) -> String

    WasiResponseOutparam

    pub struct WasiResponseOutparam {
    result : Result[WasiOutgoingResponse, WasiErrorCode]?
    }

    WASI Preview 2 response-outparam sink receiving the finalized Result[WasiOutgoingResponse, WasiErrorCode].

    WasiResponseOutparam::WasiResponseOutparam

    fn WasiResponseOutparam::WasiResponseOutparam() -> WasiResponseOutparam

    WasiResponseOutparam::set

    WasiScheme

    pub(all) enum WasiScheme {
    Http
    Https
    Other(String)
    } derive(Eq,
    Debug
    )

    WASI Preview 2 wasi:http/types@0.2.0 URL scheme.

    WasiScheme::as_str

    fn WasiScheme::as_str(self : WasiScheme) -> String

    WasiStreamRead

    pub(all) enum WasiStreamRead {
    Chunk(Bytes)
    Closed
    } derive(Eq,
    Debug
    )

    Result of a non-blocking or blocking wasi:io/streams@0.2.0 read operation.

    handle_incoming_request

    Handles a WASI HTTP incoming-request using a @core.App, draining any ExecutionContext::wait_until tasks before returning WasiOutgoingResponse.

    handle_wasi_component_request

    async fn handle_wasi_component_request(app :
    App
    , host : &WasiStreamHost, incoming_req : WasiHandle, response_out : WasiHandle, env? :
    Env
    , read_chunk_bytes? : Int64) -> Unit

    Handles a WASI Preview 2 wasi:http/incoming-handler@0.2.0 invocation using streaming incoming-body -> @http.Body::Stream and chunked outgoing-body streaming (preserving SSE).