spring-cloud / spring-cloud-netflix

Integration with Netflix OSS components
http://cloud.spring.io/spring-cloud-netflix/
Apache License 2.0
4.87k stars 2.44k forks source link

CloseableHttpClient decompresses gzip data by default #1480

Closed tranhungt closed 7 years ago

tranhungt commented 7 years ago

The http client by default decompresses the GZIP data and therefore does not pass on the response exactly as it received from downstream services. This is an issue when the user request compressed (gzip) data via accept-encoding header, which the downstream respects by sending compressed gzip, but zuul changes the response signature by decompressing the response.

The solution is to add .disableContentCompression() on the httpClientBuilder.

http://stackoverflow.com/questions/30216375/extracting-gzip-data-from-apache-httpclient-without-decompression

https://github.com/spring-cloud/spring-cloud-netflix/blob/master/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/SimpleHostRoutingFilter.java#L236

ryanjbaxter commented 7 years ago

@tranhungt how about a PR?

tranhungt commented 7 years ago

@ryanjbaxter Sure thing, glad to. :)

lifeisfoo commented 7 years ago

I'm facing the same issue and I've created a test project https://github.com/lifeisfoo/zuul-no-gzip-response.

Run the project and call GET http://localhost:9090/httbin/gzip with the "Accept-Encoding: gzip" header.

tranhungt commented 7 years ago

Not sure where to put the tests for this. @ryanjbaxter ?

ryanjbaxter commented 7 years ago

If the changes were made in SimpleHostRoutingFilter how about in SimpleHostRoutingFilterTests https://github.com/spring-cloud/spring-cloud-netflix/blob/12fff7c97f04f6000c74db066e92c87d9071ea4d/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/SimpleHostRoutingFilterTests.java

gvdenbro commented 7 years ago

@tranhungt are you still planning a pull request? I stumbled on the exact same issue, and temporarily fixed it on my project by subclassing the filter, but I would rather see a permanent fix in the root filter.

tranhungt commented 7 years ago

@gvdenbro yeah, sorry, I've just been busy with finishing up projects at work for end of year. Will put in the PR over the holidays. :)

I'm glad you got a temporary solution to work though!

tranhungt commented 7 years ago

@ryanjbaxter Thanks for the wait and recommendation. PR is up now. Let me know if it looks good with you. //cc @gvdenbro https://github.com/spring-cloud/spring-cloud-netflix/pull/1591