Parse Accept-Encoding header, and set Content-Encoding correctly#305
Conversation
Codecov Report
@@ Coverage Diff @@
## master #305 +/- ##
==========================================
+ Coverage 72.29% 72.68% +0.39%
==========================================
Files 61 61
Lines 3295 3332 +37
==========================================
+ Hits 2382 2422 +40
+ Misses 820 817 -3
Partials 93 93
Continue to review full report at Codecov.
|
|
|
||
| selectedEncoding, err := parseAcceptEncoding(hdr) | ||
| if err != nil { | ||
| // todo if a selectedEncoding is now known by a service, it should reply 406 Not Acceptable |
There was a problem hiding this comment.
The proper decision of whether to respond 406 might be better done somewhere else. This middleware might be or might not be a good place for it. Ideally, there should be some kind of orchestrator that manages such "global" decisions for request.
This decision is definitely out of the scope of compression middleware change only. I believe it's better to have this changed incrementally and not inflate the current scope.
A practice that I am used to in order to postpone such decisions, is creating a todo and opening an issue after the change has been merged. Without a todo that you can refer to in that issue, this might get lost.
How do you recommend doing this?
There was a problem hiding this comment.
Why can this not be just an http status error returned here? Middlewares in Go just write directly to the response writer, that's why they have it also as an argument.
7b4d018 to
913f1b1
Compare
Issue beatlabs#300, beatlabs#301 diff --git a/component/http/middleware.go b/component/http/middleware.go index 70c9bff..ea4446b 100644 --- a/component/http/middleware.go +++ b/component/http/middleware.go @@ -322,7 +322,7 @@ func MiddlewareChain(f http.Handler, mm ...MiddlewareFunc) http.Handler { } func isCompressionHeader(h string) bool { - return strings.Contains(h, "gzip") || strings.Contains(h, "deflate") + return strings.Contains(h, gzipHeader) || strings.Contains(h, deflateHeader) } func logRequestResponse(corID string, w *responseWriter, r *http.Request) {
…move preliminary header check Issue beatlabs#300, beatlabs#301
e072242 to
d0ffa91
Compare
ced87cb to
00f5251
Compare
tpaschalis
left a comment
There was a problem hiding this comment.
LGTM, thanks for your input Alexey!
08f5e2c to
08648d7
Compare
08648d7 to
b1dd88d
Compare
Issue #300, #301
Which problem is this PR solving?
Resolves issues #300 and #301
Short description of the changes
Accept-Encodingheader is now parsed and respected in compression middlewareContent-Encodingheader is not correctly set