https://kotlinlang.org logo
#ktor
Title
# ktor
m

Marcin Wisniowski

09/05/2019, 9:15 AM
How do I use compression with ktor client? I added an "Accept-Encoding: gzip, deflate" header to my requests, and now the responses I get are compressed. How do I make ktor decompress them?
e

e5l

09/05/2019, 9:17 AM
Hi @Marcin Wisniowski, you can use
ContentEncoding
feature: https://api.ktor.io/1.2.4/io.ktor.client.features.compression/-content-encoding.html
c

cy

09/05/2019, 9:24 AM
Note that you don’t need to set Accept-Encoding header with this feature (it is set automatically)
m

Marcin Wisniowski

09/05/2019, 9:24 AM
I'm having a hard time enabling that, where do I enable it? It's not on the https://ktor.io/clients/http-client/features page.
m

Marcin Wisniowski

09/05/2019, 9:29 AM
https://ss.nohus.eu/14031/ac13d689 Not sure what am I doing wrong 😕
Do I need some separate artifact for this?
e

e5l

09/05/2019, 9:30 AM
Yep:
:ktor-client:ktor-client-encoding-jvm:version
m

Marcin Wisniowski

09/05/2019, 9:40 AM
Works now, thank you!
e

e5l

09/05/2019, 9:41 AM
Awesome 🙂
m

Marcin Wisniowski

09/05/2019, 9:59 AM
https://github.com/ktorio/ktor/issues/1189 Is this going to be fixed?
gzip()
doesn't work, only
deflate()
. 😐 Guess I will stick with
deflate()
, apparently it's faster anyway.
e

edenman

02/11/2021, 8:26 PM
in case anybody else comes across this old thread:
gzip()
is working great for me once i added the deps
i spoke too soon: it’s broken when you get a ResponseException 😭
130 Views