diff --git a/pkg/middlewares/compress/brotli/brotli.go b/pkg/middlewares/compress/brotli/brotli.go index 17225f252..27802b0f6 100644 --- a/pkg/middlewares/compress/brotli/brotli.go +++ b/pkg/middlewares/compress/brotli/brotli.go @@ -160,6 +160,7 @@ func (r *responseWriter) Write(p []byte) (int, error) { } if !found { r.compressionDisabled = true + r.rw.WriteHeader(r.statusCode) return r.rw.Write(p) } } @@ -167,6 +168,7 @@ func (r *responseWriter) Write(p []byte) (int, error) { for _, excludedContentType := range r.excludedContentTypes { if excludedContentType.equals(mediaType, params) { r.compressionDisabled = true + r.rw.WriteHeader(r.statusCode) return r.rw.Write(p) } } diff --git a/pkg/middlewares/compress/brotli/brotli_test.go b/pkg/middlewares/compress/brotli/brotli_test.go index 005587411..67c794c46 100644 --- a/pkg/middlewares/compress/brotli/brotli_test.go +++ b/pkg/middlewares/compress/brotli/brotli_test.go @@ -356,7 +356,7 @@ func Test_ExcludedContentTypes(t *testing.T) { h := mustNewWrapper(t, cfg)(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.Header().Set(contentType, test.contentType) - rw.WriteHeader(http.StatusOK) + rw.WriteHeader(http.StatusAccepted) _, err := rw.Write(bigTestBody) require.NoError(t, err) @@ -368,7 +368,7 @@ func Test_ExcludedContentTypes(t *testing.T) { rw := httptest.NewRecorder() h.ServeHTTP(rw, req) - assert.Equal(t, http.StatusOK, rw.Code) + assert.Equal(t, http.StatusAccepted, rw.Code) if test.expCompression { assert.Equal(t, "br", rw.Header().Get(contentEncoding)) @@ -460,7 +460,7 @@ func Test_IncludedContentTypes(t *testing.T) { h := mustNewWrapper(t, cfg)(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.Header().Set(contentType, test.contentType) - rw.WriteHeader(http.StatusOK) + rw.WriteHeader(http.StatusAccepted) _, err := rw.Write(bigTestBody) require.NoError(t, err) @@ -472,7 +472,7 @@ func Test_IncludedContentTypes(t *testing.T) { rw := httptest.NewRecorder() h.ServeHTTP(rw, req) - assert.Equal(t, http.StatusOK, rw.Code) + assert.Equal(t, http.StatusAccepted, rw.Code) if test.expCompression { assert.Equal(t, "br", rw.Header().Get(contentEncoding))