diff --git a/docs/content/middlewares/http/compress.md b/docs/content/middlewares/http/compress.md index eec8e73b0..cd49d757b 100644 --- a/docs/content/middlewares/http/compress.md +++ b/docs/content/middlewares/http/compress.md @@ -55,7 +55,7 @@ http: Responses are compressed when the following criteria are all met: * The `Accept-Encoding` request header contains `gzip`, `*`, and/or `br` with or without [quality values](https://developer.mozilla.org/en-US/docs/Glossary/Quality_values). - If the `Accept-Encoding` request header is absent, it is meant as br compression is requested. + If the `Accept-Encoding` request header is absent, the response won't be encoded. If it is present, but its value is the empty string, then compression is disabled. * The response is not already compressed, i.e. the `Content-Encoding` response header is not already set. * The response`Content-Type` header is not one among the [excludedContentTypes options](#excludedcontenttypes). diff --git a/pkg/middlewares/compress/compress.go b/pkg/middlewares/compress/compress.go index b7ae85b4d..4618a0a12 100644 --- a/pkg/middlewares/compress/compress.go +++ b/pkg/middlewares/compress/compress.go @@ -92,11 +92,11 @@ func (c *compress) ServeHTTP(rw http.ResponseWriter, req *http.Request) { return } - // Client allows us to do whatever we want, so we br compress. - // See https://www.rfc-editor.org/rfc/rfc9110.html#section-12.5.3 + // Client doesn't specify a preferred encoding, for compatibility don't encode the request + // See https://github.com/traefik/traefik/issues/9734 acceptEncoding, ok := req.Header["Accept-Encoding"] if !ok { - c.brotliHandler.ServeHTTP(rw, req) + c.next.ServeHTTP(rw, req) return } diff --git a/pkg/middlewares/compress/compress_test.go b/pkg/middlewares/compress/compress_test.go index 23d6d765e..44e28b11f 100644 --- a/pkg/middlewares/compress/compress_test.go +++ b/pkg/middlewares/compress/compress_test.go @@ -10,7 +10,6 @@ import ( "net/textproto" "testing" - "github.com/andybalholm/brotli" "github.com/klauspost/compress/gzhttp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -35,7 +34,7 @@ func TestNegotiation(t *testing.T) { }{ { desc: "no accept header", - expEncoding: "br", + expEncoding: "", }, { desc: "unsupported accept header", @@ -151,7 +150,7 @@ func TestShouldNotCompressWhenContentEncodingHeader(t *testing.T) { assert.EqualValues(t, rw.Body.Bytes(), fakeCompressedBody) } -func TestShouldCompressWhenNoAcceptEncodingHeader(t *testing.T) { +func TestShouldNotCompressWhenNoAcceptEncodingHeader(t *testing.T) { req := testhelpers.MustNewRequest(http.MethodGet, "http://localhost", nil) fakeBody := generateBytes(gzhttp.DefaultMinSize) @@ -167,12 +166,9 @@ func TestShouldCompressWhenNoAcceptEncodingHeader(t *testing.T) { rw := httptest.NewRecorder() handler.ServeHTTP(rw, req) - assert.Equal(t, brotliValue, rw.Header().Get(contentEncodingHeader)) - assert.Equal(t, acceptEncodingHeader, rw.Header().Get(varyHeader)) - - got, err := io.ReadAll(brotli.NewReader(rw.Body)) - require.NoError(t, err) - assert.Equal(t, got, fakeBody) + assert.Empty(t, rw.Header().Get(contentEncodingHeader)) + assert.Empty(t, rw.Header().Get(varyHeader)) + assert.EqualValues(t, rw.Body.Bytes(), fakeBody) } func TestShouldNotCompressWhenIdentityAcceptEncodingHeader(t *testing.T) {