Content encoding
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.
Add dependencies
To use ContentEncoding
, you need to include the ktor-client-encoding
artifact in the build script:
You can learn more about artifacts required by the Ktor client from Adding client dependencies.
Install ContentEncoding
To install ContentEncoding
, pass it to the install
function inside a client configuration block:
Configure ContentEncoding
The example below shows how to enable the deflate
and gzip
encoders on the client with the specified quality values:
If required, you can implement the ContentEncoder
interface to create a custom encoder and pass it to the customEncoder
function.