Resource

response

Represents an HTTP Response.

resource response;

F get-status-code

get-status-code: func() -> status-code;

Get the HTTP Status Code for the Response.

F set-status-code

set-status-code: func(status-code: status-code) -> result​<_, _>;

Set the HTTP Status Code for the Response. Fails if the status-code given is not a valid http status code.

F get-headers

get-headers: func() -> headers;

Get the headers associated with the Response.

The returned headers resource is immutable: set, append, and delete operations will fail with header-error.immutable.

F new

new: func(headers: headers, contents: option​<stream​<u8>>, trailers: future​<result​<option​<trailers>, error-code>>) -> tuple​<response, future​<result​<_, error-code>>>;

Construct a new response, with a default status-code of 200. If a different status-code is needed, it must be set via the set-status-code method.

headers is the HTTP Headers for the Response.

contents is the optional body content stream with none representing a zero-length content stream. Once it is closed, trailers future must resolve to a result. If trailers resolves to an error, underlying connection will be closed immediately.

The returned future resolves to result of transmission of this response.

F consume-body

consume-body: func(this: response, res: future​<result​<_, error-code>>) -> tuple​<stream​<u8>, future​<result​<option​<trailers>, error-code>>>;

Get body of the Response.

Stream returned by this method represents the contents of the body. Once the stream is reported as closed, callers should await the returned future to determine whether the body was received successfully. The future will only resolve after the stream is reported as closed.

This function takes a res future as a parameter, which can be used to communicate an error in handling of the response.

Note that function will move the response, but references to headers acquired from it previously will remain valid.