Hi! I try to encode request body like <https://kto...
# ktor
t
Hi! I try to encode request body like https://ktor.io/docs/client-content-encoding.html#encode_request_body But adding
compress("gzip")
doesn't change anything.
Copy code
val client = HttpClient(CIO) {
    install(ContentEncoding)
}
val payload: String = client.get("<https://google.com>").bodyAsText()
val res = <http://client.post|client.post>("<https://postman-echo.com/post>") {
    compress("gzip")
    setBody(payload)
}
println(res.bodyAsText())
m
Compression should be transparent for your application code. Have you checked with Wireshark or some external tool whether it's gzipped on the wire?
👀 1
to elaborate: the gzip compression encoding will be picked up by the remote (
<http://postman-echo.com|postman-echo.com>
in your case) and decoded by their server before it's actually processed by any logic. Then it might also compress the response (or not) which in turn would be decompressed transparently by the ktor client and passed back to your application in uncompressed form. In HTTP terms, the
Content-Encoding
header is processed separately and the data on the wire only conforms to the
Content-Type
header after having undergone processing of
Content-Encoding
. S.a. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
👀 1
t
I've found the right solution
Copy code
install(ContentEncoding) {
    mode = ContentEncodingConfig.Mode.All
    deflate()
    gzip()
}