6.54. kink/http/RESP

6.54.1. type resp

`resp` is an HTTP response.

6.54.1.1. Resp.req

`req` method returns the `req` value which directly produced `Resp`.

If the response is a result of redirections, this method returns the `req` value of the last request in the redirection chain.

6.54.1.2. Resp.status

`status` returns the status code of the response as an integer `num`.

6.54.1.3. Resp.headers

`headers` returns a `map` of the header fields of the response.

The keys of the `map` is `str` values of the header field names. The keys are case-insensitive, as specified in [RFC 9110 - 5.1].

The values of the `map` are a `vec` of `str` values of the fields values corresponding to the field name. Bytes in the range [0x80, 0xff] (obs-text in [RFC 9110]) in field values are mapped to U+0080-U+00ff.

6.54.1.4. Resp.content

`content` returns the `resp_content` value.

Media type

If the response has multiple Content-Type header fields, which is an error according to [RFC 9110], `media_type` property of the result `resp_content` will be the last syntactically valid value.

If there is no Content-Type field value which is syntactically valid, `media_type` property falls back to application/octet-stream. This behavior is what [RFC 9110 - 8.3] specifies that recipients MAY do.

6.54.1.5. Resp.redirect_count

`redirect_count` returns the number of redirects until `Resp`.

The result will be equal to Resp.req.redirect_count.

6.54.1.6. Resp.close(...[$config={}])

`close` method closes the input stream of the response.

Config methods:

• C.on_success($success): default = {}

• C.on_error($error): default = {(:Exc) Exc.raise }

If `Resp` is created with C.stream_resp option, you need to close the input stream by `close` method.

If C.stream_resp is not specified, you still can call `close` method, but it is not required.

Result

If the stream is successfully closed, `close` tail-calls $success with no arg.

If an IO error occurs, `close` tail-calls $error with an `exception`.

Preconditions

$success must be a thunk.

$error must be a function which takes an `exception`.

6.54.2. RESP.new(Req Status Content ...[$config={}])

`new` returns a new `resp` value.

Config method:

• C.header(Header_name Header_val): can be called multiple times

The pair (Header_name, Header_val) is added as a header entry of the response.

Preconditions

`Req` must be a `req` value.

`Status` must be an integer `num` value in the range [100, 599].

`Content` must be a `resp_content` value.

`Header_name` must be a `str` of a “token” defined in [RFC 9110].

`Header_val` must be a `str` which matches /|[\x21-\x7e\x80-\xff]([\t\x20-\x7e\x80-\xff]*[\x21-\x7e\x80-\xff])?/. This assumes that a “field-value” defined in [RFC 9110] is decoded by ISO-8859-1 charset.

6.54.3. RESP.is?(Val)

`is?` returns whether `Val` is a `resp` value.