6.55. kink/http/RESP_CONTENT

6.55.1. type resp_content

`resp_content` is a HTTP response content.

A `resp_content` contains the following properties.

• input: An `input` value which reads bytes of the response content.

• media_type: The `media_type` value of the response content.

• bin (optional): A `bin` value of the bytes of the response content. If this property is given, the value is equal to bytes read from the `input` property.

6.55.1.1. Rsc.input

`input` method returns the `input` property.

6.55.1.2. Rsc.media_type

`media_type` method returns the `media_type` property.

6.55.1.3. Rsc.have_bin?

`have_bin?` returns whether `Rsc` has `bin` property.

6.55.1.4. Rsc.bin

`bin` method returns the `bin` property.

Precondition

`Rsc` must have `bin` property.

6.55.1.5. Rsc.text

`text` method returns the response content as a `str` value.

The content is decoded by `Rsc.media_type.charset`. Conversion errors are replaced to replacement characters.

Precondition

`Rsc` must have `bin` property.

6.55.1.6. Rsc.close(...[$config={}])

`close` method closes the `input` property.

Config methods:

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

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

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

If the 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.55.2. RESP_CONTENT.from_bin(Bin Mt)

`from_bin` returns a `resp_content` whose bytes is given as a `bin` value.

The properties of the result `resp_content` will be (input=Bin_input, media_type=Mt, bin=Bin), where `Bin_input` is an `input` value which reads the bytes of `Bin`.

You don't need to close the result `resp_content`.

Preconditions

`Bin` must be a `bin` value.

`Mt` must be a `media_type` value.

6.55.3. RESP_CONTENT.from_input(In Mt)

`from_input` returns a `resp_content` made from an `input` value.

The properties of the result `resp_content` will be (input=In, media_type=Mt).

You need to close the result `resp_content`.

Preconditions

`In` must be an `input` value.

`Mt` must be a `media_type` value.

6.55.4. RESP_CONTENT.is?(Val)

`is?` returns whether `Val` is a `resp_content`.