Description
Hi,
I am using openfeign with spring-cloud-starter-openfeign 2.1.1.RELEASE, the openfeign components included are of version 10.1.0. My question is that seems the default client doesn't take the response of decompress response body. This behavior caused some decoder exception like below:
com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens
at [Source: (PushbackInputStream); line: 1, column: 2]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1804) ~[jackson-core-2.9.8.jar:2.9.8]
...
org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:102) ~[spring-web-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.cloud.openfeign.support.SpringDecoder.decode(SpringDecoder.java:59) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.cloud.openfeign.support.ResponseEntityDecoder.decode(ResponseEntityDecoder.java:62) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at feign.optionals.OptionalDecoder.decode(OptionalDecoder.java:36) ~[feign-core-10.1.0.jar:na]
at feign.SynchronousMethodHandler.decode(SynchronousMethodHandler.java:176) ~[feign-core-10.1.0.jar:na]
I am not quite sure should I try to adapt the compressed response in a Client.Default, or just turn to other client implementation likes feign-httpclient? Thanks for any clarification.
Activity
kdavisk6 commentedon Apr 8, 2019
I suspect that compression is out-of-scope for any of the clients without additional configuration. I'll look it over.
kdavisk6 commentedon Apr 9, 2019
@flyingzhang
The default client does support GZIP if you set the appropriate
Content-Encoding
header. Do you have that header set and with the appropriate values?[-]The default client with URLConnection doesn't work with compressed response[/-][+]The default client with URLConnection doesn't work with gzipped response[/+]flyingzhang commentedon Apr 11, 2019
@kdavisk6 The Accept-Encoding header has been automatically set to 'gzip, deflate'. 'Content-Encoding' may not related to this issue at all.
I created a simple demo repo at https://github.com/flyingzhang/feign-client-compress-demo for this. When response is gzipped, exception will be thrown on feign's decoding.
Apparently this is somehow JRE related. In my environment armed with oracle 8u144, testing show that URLConnection can automatically decompress 'deflate' body, but won't handle the 'gzipped' response. I will test whether some latest jre can handle it well.
lucasoares commentedon Oct 9, 2020
Same here.
After adding @headers("Accept-Encoding: gzip") to the request method.
I'm using the
feign.jackson.JacksonDecoder
and not on a Spring Context, it's only OpenFeign:kdavisk6 commentedon Dec 29, 2020
I believe I may have finally found the issue here. It appears that we need to wrap the the response input stream into a
GZipInputStream
. I'll mark this as a bug.OpenFeignGH-934: Update Default Client to wrap GZIP Responses correctly
OpenFeignGH-934: Update Default Client to wrap GZIP Responses correctly
OpenFeignGH-934: Update Default Client to wrap GZIP Responses correctly
7 remaining items