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

spring.server.compression conflict with feign.compression #145

Closed
Flamingo93 opened this issue Mar 12, 2019 · 3 comments
Closed

spring.server.compression conflict with feign.compression #145

Flamingo93 opened this issue Mar 12, 2019 · 3 comments
Labels
invalid This doesn't seem right

Comments

@Flamingo93
Copy link

Flamingo93 commented Mar 12, 2019

We can enable GZip compression in Spring Boot by

server.compression.enabled=true
server.compression.mime-types=text/xml,application/xml,application/json
server.compression.min-response-size=1024

We also can enable the request or response GZIP compression for ourFeign requests by

feign.compression.request.enabled=true
feign.compression.response.enabled=true
feign.compression.request.mime-types=text/xml,application/xml,application/json
feign.compression.request.min-request-size=1024

When we config server.compression.enabled=true in server-side and feign.compression.response.enabled=true at the same time. There will be something wrong:
The server can handle the request as normal, but the client recieve wrong response.

There is an example in my github to reproduce the problem.

Reproduce problem steps:

  1. Run the server application
  2. Run the client application
  3. HTTP GET from http://localhost:8002/client/get

Phenomenon:

  1. Under normal circumstances, we will get the normal response, "String from server".
  2. But when we config server.compression.enabled=true in server-side and feign.compression.response.enabled=true in client-side at the same time, we will get garbled, like ".)��KWH+��U(N-*K-�".
@OlgaMaciaszek
Copy link
Collaborator

OlgaMaciaszek commented Apr 2, 2019

@Flamingo93 As you can read the documentation and the javadocs in FeignAcceptGzipEncodingInterceptor in openfeign. You will see that unlike server.compression.enabled=true in Spring, which actually causes the response to be encoded, the feign.compression.response.enabled=true in OpenFeign is only responsible to adding the Accept-Encoding=["gzip", "deflated"] headers, therefore indicating to the server that the client expects an encoded response. OpenFeign does not offer decoding functionality. I don't think they are planning to add it, but in any case, it would have to be handled within an OpenFeign issue, as we only provide integration for existing OpenFeign functionalities.

You can decode the response in your client app on your own, for example, using java.util.zip.GZIPInputStream and java.io.Reader.

As a side note, I would encourage you to upgrade your dependencies (Spring Boot 1.4.x is no longer supported and we'll be ending the support for Spring Cloud Edgware Release train in 3 months) and to using the dependency management plugin with the release train name rather than manually specifying Spring Cloud dependencies versions (you can generate a correct pom for the required versions at start.spring.io.

@OlgaMaciaszek OlgaMaciaszek added invalid This doesn't seem right and removed in progress labels Apr 2, 2019
@OlgaMaciaszek OlgaMaciaszek removed their assignment Apr 2, 2019
@Flamingo93
Copy link
Author

@OlgaMaciaszek Thanks for your reply. Your explaination is good, but I still has some question.

This is my thought: feign.compression.response.enabled=true indicated to the server that the client expects an encoded response, so the server will encode response. But server.compression.enabled=true still ask server to encode response, so the response was encoded twice which cause the problem. Is it right?

@jskim1991
Copy link
Contributor

Hello,
I had the same issue as @Flamingo93.
I tried the workaround mentioned here and it worked.
So I was wondering what if we change the default decoder to handle gzip as well as regular responses so that everyone can make use of it automatically?

This issue is being transferred. Timeline may not be complete until it finishes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

5 participants