Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The default client with URLConnection doesn't work with gzipped response #934

Closed
flyingzhang opened this issue Apr 2, 2019 · 5 comments · Fixed by #1349
Closed

The default client with URLConnection doesn't work with gzipped response #934

flyingzhang opened this issue Apr 2, 2019 · 5 comments · Fixed by #1349
Labels
bug Unexpected or incorrect behavior

Comments

@flyingzhang
Copy link

flyingzhang commented Apr 2, 2019

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.

@kdavisk6 kdavisk6 added the question General usage or 'how-to' questions label Apr 8, 2019
@kdavisk6
Copy link
Member

kdavisk6 commented 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 kdavisk6 added the documentation Issues that require updates to our documentation label Apr 8, 2019
@kdavisk6
Copy link
Member

kdavisk6 commented 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?

@flyingzhang flyingzhang changed the title The default client with URLConnection doesn't work with compressed response The default client with URLConnection doesn't work with gzipped response Apr 11, 2019
@flyingzhang
Copy link
Author

@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.

@kdavisk6 kdavisk6 removed the documentation Issues that require updates to our documentation label Dec 30, 2019
@lucasoares
Copy link

lucasoares commented Oct 9, 2020

Same here.

Exception in thread "main" feign.FeignException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens

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:

    <dependency>
      <groupId>io.github.openfeign</groupId>
      <artifactId>feign-core</artifactId>
      <version>11.0</version>
    </dependency>
    <dependency>
      <groupId>io.github.openfeign</groupId>
      <artifactId>feign-okhttp</artifactId>
      <version>11.0</version>
    </dependency>
    <dependency>
      <groupId>io.github.openfeign</groupId>
      <artifactId>feign-jackson</artifactId>
      <version>11.0</version>
    </dependency>
    <dependency>
      <groupId>io.github.openfeign</groupId>
      <artifactId>feign-mock</artifactId>
      <version>11.0</version>
      <scope>test</scope>
    </dependency>

@kdavisk6
Copy link
Member

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.

@kdavisk6 kdavisk6 added bug Unexpected or incorrect behavior and removed question General usage or 'how-to' questions labels Dec 29, 2020
kdavisk6 added a commit to kdavisk6/feign that referenced this issue Dec 29, 2020
This change updates the Input Stream handling when using the Default
client implementation to detect when a response is `gzipped` and
wrap it in a `GZipInputStream`.

This addresses any issues related to compression when using the
default client.
kdavisk6 added a commit to kdavisk6/feign that referenced this issue Dec 29, 2020
This change updates the Input Stream handling when using the Default
client implementation to detect when a response is `gzipped` and
wrap it in a `GZipInputStream`.

This addresses any issues related to compression when using the
default client.
kdavisk6 added a commit to kdavisk6/feign that referenced this issue Dec 31, 2020
This change updates the Input Stream handling when using the Default
client implementation to detect when a response is `gzipped` and
wrap it in a `GZipInputStream`.

This addresses any issues related to compression when using the
default client.
kdavisk6 added a commit that referenced this issue Jan 8, 2021
Fixes: #934, #1208

This change updates the Input Stream handling when using the Default
client implementation to detect when a response is `gzipped` and
wrap it in a `GZipInputStream`.

This addresses any issues related to compression when using the
default client.

In addition, removed the implicit parsing of the
body during toString.  This was also brought up in #1208 and it came up
during testing of this change.  Users should be using our `asReader`
and other methods to access the response body.

* Adding Deflate support
* Added Deflate Support and removed implicit response body reading
* Refactored Gzip and Deflate Conditions
* Corrected formatting and line-endings
kdavisk6 added a commit that referenced this issue Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants