Required dependencies: io.ktor:%artifact_name%
The Ktor client provides the ContentEncoding plugin that allows you to enable specified compression algorithms (such as gzip
and deflate
) and configure their settings. This plugin serves two primary purposes:
- Sets the
Accept-Encoding
header with the specified quality value. - Decodes content received from a server to obtain the original payload.
To use ContentEncoding
, you need to include the %artifact_name%
artifact in the build script:
To install ContentEncoding
, pass it to the install
function inside a client configuration block:
val client = HttpClient(CIO) {
install(ContentEncoding)
}
The example below shows how to enable the deflate
and gzip
encoders on the client with the specified quality values:
{src="snippets/client-content-encoding/src/main/kotlin/com/example/Application.kt" lines="13-18"}
If required, you can implement the ContentEncoder
interface to create a custom encoder and pass it to the customEncoder
function.