Skip to content

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

Closed
@flyingzhang

Description

@flyingzhang

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

kdavisk6 commented on Apr 8, 2019

@kdavisk6
Member

I suspect that compression is out-of-scope for any of the clients without additional configuration. I'll look it over.

kdavisk6

kdavisk6 commented on Apr 9, 2019

@kdavisk6
Member

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

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[/+] on Apr 11, 2019
flyingzhang

flyingzhang commented on Apr 11, 2019

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

removed
documentationIssues that require updates to our documentation
on Dec 30, 2019
lucasoares

lucasoares commented on Oct 9, 2020

@lucasoares

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

kdavisk6 commented on Dec 29, 2020

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

added
bugUnexpected or incorrect behavior
and removed
questionGeneral usage or 'how-to' questions
on Dec 29, 2020
added a commit that references this issue on Dec 29, 2020

OpenFeignGH-934: Update Default Client to wrap GZIP Responses correctly

added 2 commits that reference this issue on Dec 29, 2020

OpenFeignGH-934: Update Default Client to wrap GZIP Responses correctly

OpenFeignGH-934: Update Default Client to wrap GZIP Responses correctly

7 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUnexpected or incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @flyingzhang@kdavisk6@lucasoares

      Issue actions

        The default client with URLConnection doesn't work with gzipped response · Issue #934 · OpenFeign/feign