Ktor 3.0.0-beta-2 Help

BOM remover

Byte Order Mark (BOM) is a character encoded in a Unicode file or stream. The main purpose of BOM is to signal the text's stream encoding and the byte order of 16-bit and 32-bit encodings.

In some cases, it is necessary to remove BOM from the response body. For example, in the UTF-8 encoding, the presence of BOM is optional, and it may cause problems when it's read by software that does not know how to handle the BOM.

The Ktor client provides the BOMRemover plugin that removes BOM from the response body in the UTF-8, UTF-16 (BE), UTF-16 (LE), UTF-32 (BE) and UTF-32 (LE) encodings.

Add dependencies

To use BOMRemover, you need to include the ktor-client-bom-remover artifact in the build script:

implementation("io.ktor:ktor-client-bom-remover:$ktor_version")
implementation "io.ktor:ktor-client-bom-remover:$ktor_version"
<dependency> <groupId>io.ktor</groupId> <artifactId>ktor-client-bom-remover-jvm</artifactId> <version>${ktor_version}</version> </dependency>

You can learn more about artifacts required by the Ktor client from Adding client dependencies.

Install BOMRemover

To install BOMRemover, pass it to the install function inside a client configuration block:

import io.ktor.client.* import io.ktor.client.engine.cio.* import io.ktor.client.plugins.compression.* //... val client = HttpClient(CIO) { install(BOMRemover) }
Last modified: 30 April 2024