Skip to content

Latest commit

 

History

History
42 lines (31 loc) · 1.93 KB

content-encoding.md

File metadata and controls

42 lines (31 loc) · 1.93 KB

Required dependencies: io.ktor:%artifact_name%

The ContentEncoding plugin allows you to enable specified compression algorithms (such as 'gzip' and 'deflate') and configure their settings.

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 {id="add_dependencies"}

To use ContentEncoding, you need to include the %artifact_name% artifact in the build script:

Install ContentEncoding {id="install_plugin"}

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

val client = HttpClient(CIO) {
    install(ContentEncoding)
}

Configure ContentEncoding {id="configure_plugin"}

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.