Skip to content
Menu
Contents

Reading the tags

pure

Same arguments, same result; touches nothing outside.

pure if arg2 is

Pure when that argument is a pure function; otherwise as impure as it is.

impure

Reads or changes something outside the program.

WasiHttp

12 types23 functions

The component target's HTTP server: serve runs an Http handler as a wasi:http/incoming-handler export, over the wasi:http/types views below. Every handle is dropped explicitly, a child before its parent.

At a glance

  • @Fields

    The fields resource of wasi:http/types@0.2.3, as a handle.

  • @IncomingRequest

    The incoming-request resource of wasi:http/types@0.2.3, as a handle.

  • @ResponseOutparam

    The response-outparam resource of wasi:http/types@0.2.3, as a handle.

  • @IncomingBody

    The incoming-body resource of wasi:http/types@0.2.3, as a handle.

  • @OutgoingResponse

    The outgoing-response resource of wasi:http/types@0.2.3, as a handle.

  • @OutgoingBody

    The outgoing-body resource of wasi:http/types@0.2.3, as a handle.

  • Scheme

    The view of WIT's scheme type, from wasi:http/types@0.2.3.

  • HeaderError

    The view of WIT's header-error type, from wasi:http/types@0.2.3.

  • ErrorCode

    The view of WIT's error-code type, from wasi:http/types@0.2.3.

  • DNSErrorPayload

    The view of WIT's DNS-error-payload type, from wasi:http/types@0.2.3.

  • TLSAlertReceivedPayload

    The view of WIT's TLS-alert-received-payload type, from wasi:http/types@0.2.3.

  • FieldSizePayload

    The view of WIT's field-size-payload type, from wasi:http/types@0.2.3.

  • serve

    Read the request, run handler on it, and answer with what it returns.

  • newFields

    WIT's fields constructor, from wasi:http/types@0.2.3, in Bert's view of its types.

  • fieldsEntries

    WIT's fields.entries method, from wasi:http/types@0.2.3, in Bert's view of its types.

  • fieldsAppend

    WIT's fields.append method, from wasi:http/types@0.2.3, in Bert's view of its types.

  • incomingRequestMethod

    WIT's incoming-request.method method, from wasi:http/types@0.2.3, in Bert's view of its types.

  • incomingRequestPathWithQuery

    WIT's incoming-request.path-with-query method, from wasi:http/types@0.2.3, in Bert's view of its types.

  • incomingRequestScheme

    WIT's incoming-request.scheme method, from wasi:http/types@0.2.3, in Bert's view of its types.

  • incomingRequestAuthority

    WIT's incoming-request.authority method, from wasi:http/types@0.2.3, in Bert's view of its types.

  • incomingRequestHeaders

    WIT's incoming-request.headers method, from wasi:http/types@0.2.3, in Bert's view of its types.

  • incomingRequestConsume

    WIT's incoming-request.consume method, from wasi:http/types@0.2.3, in Bert's view of its types.

  • responseOutparamSet

    WIT's response-outparam.set static function, from wasi:http/types@0.2.3, in Bert's view of its types.

  • incomingBodyStream

    WIT's incoming-body.stream method, from wasi:http/types@0.2.3, in Bert's view of its types.

  • newOutgoingResponse

    WIT's outgoing-response constructor, from wasi:http/types@0.2.3, in Bert's view of its types.

  • outgoingResponseSetStatusCode

    A status outside 0 … 65535 traps; one the host refuses is an Err.

  • outgoingResponseBody

    WIT's outgoing-response.body method, from wasi:http/types@0.2.3, in Bert's view of its types.

  • outgoingBodyWrite

    WIT's outgoing-body.write method, from wasi:http/types@0.2.3, in Bert's view of its types.

  • outgoingBodyFinish

    WIT's outgoing-body.finish static function, from wasi:http/types@0.2.3, in Bert's view of its types.

  • dropFields

    Drops the fields handle, from wasi:http/types@0.2.3.

  • dropIncomingRequest

    Drops the incoming-request handle, from wasi:http/types@0.2.3.

  • dropResponseOutparam

    Drops the response-outparam handle, from wasi:http/types@0.2.3.

  • dropIncomingBody

    Drops the incoming-body handle, from wasi:http/types@0.2.3.

  • dropOutgoingResponse

    Drops the outgoing-response handle, from wasi:http/types@0.2.3.

  • dropOutgoingBody

    Drops the outgoing-body handle, from wasi:http/types@0.2.3.

Types

@Fields

type @Fields

The fields resource of wasi:http/types@0.2.3, as a handle. It comes only from the functions here that return one. Release it with dropFields.

@IncomingRequest

type @IncomingRequest

The incoming-request resource of wasi:http/types@0.2.3, as a handle. It comes only from the functions here that return one. Release it with dropIncomingRequest.

@ResponseOutparam

type @ResponseOutparam

The response-outparam resource of wasi:http/types@0.2.3, as a handle. It comes only from the functions here that return one. Release it with dropResponseOutparam.

@IncomingBody

type @IncomingBody

The incoming-body resource of wasi:http/types@0.2.3, as a handle. It comes only from the functions here that return one. Release it with dropIncomingBody.

@OutgoingResponse

type @OutgoingResponse

The outgoing-response resource of wasi:http/types@0.2.3, as a handle. It comes only from the functions here that return one. Release it with dropOutgoingResponse.

@OutgoingBody

type @OutgoingBody

The outgoing-body resource of wasi:http/types@0.2.3, as a handle. It comes only from the functions here that return one. Release it with dropOutgoingBody.

Scheme

Scheme = [HTTP | HTTPS | Other(String)]

The view of WIT's scheme type, from wasi:http/types@0.2.3.

HeaderError

HeaderError = [InvalidSyntax | Forbidden | Immutable]

The view of WIT's header-error type, from wasi:http/types@0.2.3.

ErrorCode

ErrorCode = [DNSTimeout | DNSError(DNSErrorPayload) | DestinationNotFound | DestinationUnavailable | DestinationIPProhibited | DestinationIPUnroutable | ConnectionRefused | ConnectionTerminated | ConnectionTimeout | ConnectionReadTimeout | ConnectionWriteTimeout | ConnectionLimitReached | TLSProtocolError | TLSCertificateError | TLSAlertReceived(TLSAlertReceivedPayload) | HTTPRequestDenied | HTTPRequestLengthRequired | HTTPRequestBodySize(Http.Option(Int)) | HTTPRequestMethodInvalid | HTTPRequestURIInvalid | HTTPRequestURITooLong | HTTPRequestHeaderSectionSize(Http.Option(Int)) | HTTPRequestHeaderSize(Http.Option(FieldSizePayload)) | HTTPRequestTrailerSectionSize(Http.Option(Int)) | HTTPRequestTrailerSize(FieldSizePayload) | HTTPResponseIncomplete | HTTPResponseHeaderSectionSize(Http.Option(Int)) | HTTPResponseHeaderSize(FieldSizePayload) | HTTPResponseBodySize(Http.Option(Int)) | HTTPResponseTrailerSectionSize(Http.Option(Int)) | HTTPResponseTrailerSize(FieldSizePayload) | HTTPResponseTransferCoding(Http.Option(String)) | HTTPResponseContentCoding(Http.Option(String)) | HTTPResponseTimeout | HTTPUpgradeFailed | HTTPProtocolError | LoopDetected | ConfigurationError | InternalError(Http.Option(String))]

The view of WIT's error-code type, from wasi:http/types@0.2.3.

DNSErrorPayload

DNSErrorPayload = { rcode: Http.Option(String), infoCode: Http.Option(Int) }

The view of WIT's DNS-error-payload type, from wasi:http/types@0.2.3.

TLSAlertReceivedPayload

TLSAlertReceivedPayload = { alertId: Http.Option(Int), alertMessage: Http.Option(String) }

The view of WIT's TLS-alert-received-payload type, from wasi:http/types@0.2.3.

FieldSizePayload

FieldSizePayload = { fieldName: Http.Option(String), fieldSize: Http.Option(Int) }

The view of WIT's field-size-payload type, from wasi:http/types@0.2.3.

Functions

serve

Read the request, run handler on it, and answer with what it returns. The response is handed to the host before its body is written: the host sends the body as it is written, so a body larger than the stream's buffer would otherwise never drain.

The request's headers are every header the host passes on, in the order it lists them, names lowercase and a header sent twice as two entries.

The whole request body is read into memory before the handler runs, and a body that arrives in more than one read is held twice while its pieces are joined. With the default 1 MiB of memory that caps a request body at about half of it, 500 KB; past it the instance runs out of memory and the host answers 500. Building with --memory raises the cap.

A status the host refuses, such as one below 100, answers 500; one outside 0 … 65535 traps, and the host answers 500 for it. A header the host refuses, a forbidden one such as connection or one whose name or value is not valid header syntax, is left out. So is a content-length the handler sets: the host frames the body itself, and a length that disagreed with the body would cut it short or break the response.

newFields

() -> @Fieldsimpure

WIT's fields constructor, from wasi:http/types@0.2.3, in Bert's view of its types.

fieldsEntries

(@Fields) -> List({ first: String, second: String })impure

WIT's fields.entries method, from wasi:http/types@0.2.3, in Bert's view of its types.

fieldsAppend

(@Fields, String, String) -> [Ok(Unit) | Err(HeaderError)]impure

WIT's fields.append method, from wasi:http/types@0.2.3, in Bert's view of its types.

incomingRequestMethod

WIT's incoming-request.method method, from wasi:http/types@0.2.3, in Bert's view of its types.

incomingRequestPathWithQuery

(@IncomingRequest) -> Http.Option(String)impure

WIT's incoming-request.path-with-query method, from wasi:http/types@0.2.3, in Bert's view of its types.

incomingRequestScheme

WIT's incoming-request.scheme method, from wasi:http/types@0.2.3, in Bert's view of its types.

incomingRequestAuthority

(@IncomingRequest) -> Http.Option(String)impure

WIT's incoming-request.authority method, from wasi:http/types@0.2.3, in Bert's view of its types.

incomingRequestHeaders

WIT's incoming-request.headers method, from wasi:http/types@0.2.3, in Bert's view of its types.

incomingRequestConsume

(@IncomingRequest) -> [Ok(@IncomingBody) | Err(Unit)]impure

WIT's incoming-request.consume method, from wasi:http/types@0.2.3, in Bert's view of its types.

responseOutparamSet

(@ResponseOutparam, [Ok(@OutgoingResponse) | Err(ErrorCode)]) -> Unitimpure

WIT's response-outparam.set static function, from wasi:http/types@0.2.3, in Bert's view of its types.

incomingBodyStream

(@IncomingBody) -> [Ok(WasiIo.@InputStream) | Err(Unit)]impure

WIT's incoming-body.stream method, from wasi:http/types@0.2.3, in Bert's view of its types.

newOutgoingResponse

WIT's outgoing-response constructor, from wasi:http/types@0.2.3, in Bert's view of its types.

outgoingResponseSetStatusCode

(@OutgoingResponse, Int) -> [Ok(Unit) | Err(Unit)]impure

A status outside 0 … 65535 traps; one the host refuses is an Err.

outgoingResponseBody

(@OutgoingResponse) -> [Ok(@OutgoingBody) | Err(Unit)]impure

WIT's outgoing-response.body method, from wasi:http/types@0.2.3, in Bert's view of its types.

outgoingBodyWrite

(@OutgoingBody) -> [Ok(WasiIo.@OutputStream) | Err(Unit)]impure

WIT's outgoing-body.write method, from wasi:http/types@0.2.3, in Bert's view of its types.

outgoingBodyFinish

(@OutgoingBody, Http.Option(@Fields)) -> [Ok(Unit) | Err(ErrorCode)]impure

WIT's outgoing-body.finish static function, from wasi:http/types@0.2.3, in Bert's view of its types.

dropFields

(@Fields) -> Unitimpure

Drops the fields handle, from wasi:http/types@0.2.3. Nothing else releases it, and the handle is not used after.

dropIncomingRequest

(@IncomingRequest) -> Unitimpure

Drops the incoming-request handle, from wasi:http/types@0.2.3. Nothing else releases it, and the handle is not used after.

dropResponseOutparam

(@ResponseOutparam) -> Unitimpure

Drops the response-outparam handle, from wasi:http/types@0.2.3. Nothing else releases it, and the handle is not used after.

dropIncomingBody

(@IncomingBody) -> Unitimpure

Drops the incoming-body handle, from wasi:http/types@0.2.3. Nothing else releases it, and the handle is not used after.

dropOutgoingResponse

(@OutgoingResponse) -> Unitimpure

Drops the outgoing-response handle, from wasi:http/types@0.2.3. Nothing else releases it, and the handle is not used after.

dropOutgoingBody

(@OutgoingBody) -> Unitimpure

Drops the outgoing-body handle, from wasi:http/types@0.2.3. Nothing else releases it, and the handle is not used after.

Reading the tags

pure

Same arguments, same result; touches nothing outside.

pure if arg2 is

Pure when that argument is a pure function; otherwise as impure as it is.

impure

Reads or changes something outside the program.