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
Adding gzip support for Spring Decoder #230
Adding gzip support for Spring Decoder #230
Conversation
@jskim1991 Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
Hi @jskim1991 thanks for you PR. Test failed please fixed it. On the other thing just exchange ideas, I see the judgment logic in The source code
So I think If the property
Any Thoughts? |
: null; | ||
|
||
if (encoding != null) { | ||
if (encoding.contains(HttpEncoding.GZIP_ENCODING)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make this behaviour optional and not turned on by default in order to maintain backwards compatibility. You can, for example make it dependant on a new property.
if (encoding != null) { | ||
if (encoding.contains(HttpEncoding.GZIP_ENCODING)) { | ||
Response build = response.toBuilder() | ||
.body(this.decompress(response).getBytes()).build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decompress(response)
can return null - add nullcheck.
.isEqualTo(new Hello("hello world via response")); | ||
} | ||
|
||
public static class Hello { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this have to be public
?
@jskim1991 Thank you for signing the Contributor License Agreement! |
@holy12345 - I agree with you, with the distinction that I still would like to see maybe an additional property used to opt in apart from |
Build seems to be failing due to a circleci-related issue. Contacting them to find out what the problem is. |
@jskim1991 I have merged this fix for the circleci issue: https://github.com/spring-cloud/spring-cloud-openfeign/pull/231/files Plese merge master to your branch to get this commit and rebuild the PR. |
@OlgaMaciaszek, thank you so much for your feedback. I will work on it to meet your directions and let you know. |
@OlgaMaciaszek, i thought about your comment on backward compatibility. If users customized feign.codec.Decoder, it doesn't use SpringDecoder and also, the logic checks for Http Header to see what content type is returned. If you really want me to add a new property, I will do so but I am not sure why that would fail in normal cases as well as when customized decoder is implemented. Please let me know. Thanks :) Edit: i guess one possible way is they do decompression part and use SpringDecoder on the decompressed response. I think your request for an additional property makes sense. |
Codecov Report
@@ Coverage Diff @@
## master #230 +/- ##
============================================
+ Coverage 76.44% 76.98% +0.53%
- Complexity 336 345 +9
============================================
Files 41 43 +2
Lines 1422 1451 +29
Branches 207 213 +6
============================================
+ Hits 1087 1117 +30
+ Misses 246 241 -5
- Partials 89 93 +4
|
@OlgaMaciaszek I committed some new changes to support backward compatibility as you requested. Please let me know if there is anything I need to change to make it better. Thanks :) Edit: I was thinking about which would be a better way to inject gzipdecoder. Let me know what you think of it.
I tried both and don't see much difference. Going with option 1 made sense to me initially since OptionalDecoder and ResponseEntityDecoder have some logic and flow to get to a specific point in SpringDecoder. So I think it is aligned with the previous design where it starts from OptionalDecoder and goes in order. |
@OlgaMaciaszek I am still waiting for your feedback |
@@ -39,7 +39,7 @@ | |||
@EnableConfigurationProperties(FeignClientEncodingProperties.class) | |||
@ConditionalOnClass(Feign.class) | |||
@ConditionalOnBean(Client.class) | |||
@ConditionalOnProperty(value = "feign.compression.response.enabled", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the havingValue
property is not necessary
@@ -42,7 +42,7 @@ | |||
// The OK HTTP client uses "transparent" compression. | |||
// If the content-encoding header is present it disable transparent compression | |||
@ConditionalOnMissingBean(type = "okhttp3.OkHttpClient") | |||
@ConditionalOnProperty(value = "feign.compression.request.enabled", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the havingValue
property is not necessary
} | ||
GZIPInputStream gzipInputStream = new GZIPInputStream( | ||
response.body().asInputStream()); | ||
BufferedReader reader = new BufferedReader( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you need to close these readers
} | ||
|
||
@Bean | ||
@ConditionalOnProperty(value = "feign.compression.response.useGzipDecoder", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add some documentation about the new property
@ryanjbaxter I have made some changes that you requested. Please let me know if there is anything else I need to change. Thanks :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but there are still some things that should be fixed.
*/ | ||
@Configuration | ||
@ConditionalOnProperty(value = "feign.compression.response.enabled", | ||
matchIfMissing = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
matchIfMissing = false
is not needed. That's the default. value =
is not needed.
import org.springframework.cloud.openfeign.encoding.HttpEncoding; | ||
|
||
/** | ||
* When response is compressed as gzip, this decompresses and uses SpringDecoder to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to {@link SpringDecoder}
@ConditionalOnProperty(value = "feign.compression.response.enabled", | ||
matchIfMissing = false) | ||
// The OK HTTP client uses "transparent" compression. | ||
// If the accept-encoding header is present it disable transparent compression |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the grammar and punctuation:
If the accept-encoding header is present, it disables transparent compression.
} | ||
|
||
@Bean | ||
@ConditionalOnProperty(value = "feign.compression.response.useGzipDecoder", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove value =
and matchIfMissing = false
. They are unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this, i see most configs use dashes between words in the documentation. Should I change this property name from camel case to dashes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spring will automatically do that
this.messageConverters = messageConverters; | ||
} | ||
|
||
@Bean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably have a @ConditionalOnMissingBean
here, i.e., if the user provides their own Decoder
implementation, that should have priority and, at the same time, ensure that this configuration is processed before the FeignClientsConfiguration
that provides its own @Bean @ConditionalOnMissingBean Decoder
.
@OlgaMaciaszek Thank you for feedback. Please let me know what else I need to change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now.
fixes #229, #145
Based on my usage of FeignClient, I was only able to get gzip content. So I only added test for gzip decompression. If there is a need to add support for other content-encoding with different types of http clients, please provide me some information and we can work on it together.
Thanks :)