apollo-kotlin: gzip server responses break JS client
Summary
gzip compressed responses currently break the apollo client on the js target, jvm works
it looks like the client uses the content-length of the response and truncates the decompressed bytes at this offset instead of consuming all the decompressed bytes.
background might be as described here https://slack-chats.kotlinlang.org/t/545061/i-think-i-ve-discovered-a-bug-with-gzip-client-handling-and-
Version
3.7.1
Steps to reproduce the behavior
do a graphql request to a server which has gzip encoding on, this results in
JsonEncodingException: Unterminated string at ...
There is also a bug in ktor https://youtrack.jetbrains.com/issue/KTOR-4653
however when we force the ktor version to 2.1.3, there is still another error from apollo client, which might somehow relate to this.
ApolloNetworkException: Expected 2161, actual 5899
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 2
- Comments: 31 (19 by maintainers)
Fixed with
3.7.4
: https://github.com/apollographql/apollo-kotlin/releases/tag/v3.7.4Thanks for the details and sorry for the delay, this stuff is hairy. I was able to reproduce with this:
It looks like a Ktor bug in the
ByteArray
conversion. I’ll dig more and update this issue. Thanks!After I’ve checked the source code and documentation of ktor, I was wondering if it’s necessary to install the
ContentEncoding
plugin of Ktor when you instantiate theKtorHttpEngine
? I’ve also tried to fiddle around with a tiny example:If I disable the plugin, then the request won’t contain an
Accept-Encoding
header, unless I explicitly set it a few lines below, but when I do so, the request fails (correctly), because the client doesn’t really expect a gzipped response. The suspicious part is that there is anAccept-Encoding
header in the outgoing requests in our case in the browser, which should not be possible according to their docs, and also to the example above.I also checked in the browser with the built-in debugger, and that
contentEncoding
variable has anull
value runtime 😕