Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/prometheus-exemplars-suppor…
Browse files Browse the repository at this point in the history
…t' into feat/prometheus-exemplars-support
  • Loading branch information
EvgeniaMartynova-thebeat committed Jan 9, 2022
2 parents a6324be + d4b073c commit cadf753
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions component/http/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,15 @@ func (w *dynamicCompressionResponseWriter) WriteHeader(statusCode int) {
case gzipHeader:
w.writer = gzip.NewWriter(w.ResponseWriter)
w.ResponseWriter.Header().Set(encoding.ContentEncodingHeader, gzipHeader)
w.ResponseWriter.Header().Del("Content-Length")
case deflateHeader:
var err error
w.writer, err = flate.NewWriter(w.ResponseWriter, w.deflateLevel)
if err != nil {
w.writer = w.ResponseWriter
} else {
w.ResponseWriter.Header().Set(encoding.ContentEncodingHeader, deflateHeader)
w.ResponseWriter.Header().Del("Content-Length")
}
case identityHeader, "":
w.ResponseWriter.Header().Set(encoding.ContentEncodingHeader, identityHeader)
Expand Down
9 changes: 7 additions & 2 deletions component/http/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,10 @@ func TestNewCompressionMiddleware(t *testing.T) {

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(202) })
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Length", "123")
w.WriteHeader(202)
})
req, err := http.NewRequest("GET", "/test", nil)
assert.NoError(t, err)

Expand All @@ -281,8 +284,10 @@ func TestNewCompressionMiddleware(t *testing.T) {
rc := httptest.NewRecorder()
compressionMiddleware(handler).ServeHTTP(rc, req)
actual := rc.Header().Get("Content-Encoding")
assert.NotNil(t, actual)
assert.Equal(t, name, actual)

cl := rc.Header().Get("Content-Length")
assert.Equal(t, "", cl)
})
}
}
Expand Down

0 comments on commit cadf753

Please sign in to comment.