-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
gzip response only if it exceeds a minimal length #2267
Conversation
If the response is too short, e.g. a few bytes, compressing the response makes it even larger. The new parameter MinLength to the GzipConfig struct allows to set a threshold (in bytes) as of which response size the compression should be applied. If the response is shorter, no compression will be applied.
I think this will break If |
@aldas Thanks for your thoughts. For the Regarding the threshold for compressing the response, I would say it depends on the application. For an API with JSON responses, a lower threshold or no threshold at all might be appropriate. But if an API has many empty responses (or a simple |
I think that field needs definitely longer description than at the moment. I you way that most of the people would not understand what they are doing and start setting random numbers there. There should be declaration of related aspects that you should consider when changing this number so there would be somewhat informed decision. |
and probably |
Any more comments on this? |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #2267 +/- ##
=======================================
Coverage 92.88% 92.89%
=======================================
Files 39 39
Lines 4526 4574 +48
=======================================
+ Hits 4204 4249 +45
- Misses 234 236 +2
- Partials 88 89 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
@ioppermann other than that test function should not consist of multiple testcases - divide it to multiple test functions or use table based tests, I think this PR is OK. After #2355 I am little bit vary of changing this middleware but I can not find any problems to block to ATM :) just to be sure I looked what other frameworks are doing - similar thing for Gin middleware https://github.com/nanmu42/gzip/blob/v1/writerwrapper.go FastHTTP does some minimal length checking https://github.com/valyala/fasthttp/blob/87cb886157ae414e178fd5bc14a57d5e1c8fcadb/http.go#L1766 @lammel could you please review this. |
@aldas I fixed the linter error from CI pipeline and I splitted up the tests such that each test only tests one thing. |
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.
LGTM!
We have all issues addressed: sane default, sync.pool, clean tests and ensure we gzip in uncertain situations.
Thnx @ioppermann , approved from my side.
Serendipitously, just read the This probably isn't the best place to request, but a tagged version would be great! |
If the response is too short, e.g. a few bytes, compressing the response makes it even larger. The new parameter MinLength to the GzipConfig struct allows to set a threshold (in bytes) as of which response size the compression should be applied. If the response is shorter, no compression will be applied.