wasi_http_transport behaviour (wasm v0.16.0)

View Source

The pluggable transport behind wasi:http.

wasi:http exposes abstract HTTP semantics and leaves the wire protocol to the host, so the client backend is a behaviour: one module per binding. wasi_http performs a guest's outbound request through the configured transport (default wasi_http_h1, HTTP/1.1), and a different binding (h2, h3) can be swapped in without the interface changing. The request and response are the abstract form the wasi:http/types resources carry; the binding turns them into wire bytes.

When the request carries an address, the binding connects to it and not to host: wasi_http resolved the name and checked that address against the guest's grant, and resolving it again could reach one it did not check. host stays the name, for TLS.

Summary

Functions

The monotonic millisecond at which Timeout from now runs out.

Whether a body of Size bytes is over the request's max_body_bytes.

The TLS options for a request to Host, naming it as the server.

How long one wait may last: Wait (a step's own timeout, or undefined for none), never past Deadline. Zero once the deadline has passed.

Types

request()

-type request() ::
          #{host := binary(),
            port := inet:port_number(),
            method := binary(),
            path := binary(),
            headers := [{binary(), binary()}],
            body := binary(),
            address => inet:ip_address(),
            scheme => binary(),
            tls => [ssl:tls_client_option()],
            connect_timeout => timeout() | undefined,
            first_byte_timeout => timeout() | undefined,
            between_bytes_timeout => timeout() | undefined,
            max_body_bytes => pos_integer()}.

response()

-type response() ::
          {ok, StatusCode :: 0..65535, Headers :: [{binary(), binary()}], Body :: binary()} |
          {error, ErrorCode :: term()}.

Callbacks

request/2

-callback request(request(), timeout()) -> response().

Functions

deadline/1

-spec deadline(timeout()) -> integer() | infinity.

The monotonic millisecond at which Timeout from now runs out.

over_limit(Size, Req)

-spec over_limit(non_neg_integer(), request()) -> boolean().

Whether a body of Size bytes is over the request's max_body_bytes.

tls_opts(Host, Tls)

-spec tls_opts(binary(), [ssl:tls_client_option()]) -> [ssl:tls_client_option()].

The TLS options for a request to Host, naming it as the server.

A binding that connects to the request's address loses the name the peer's certificate is checked against, so the name is given to TLS explicitly, unless the options already carry one or Host is itself an address.

within/2

-spec within(timeout() | undefined, integer() | infinity) -> timeout().

How long one wait may last: Wait (a step's own timeout, or undefined for none), never past Deadline. Zero once the deadline has passed.