Skip to content

compress midddleware: dont encode content if Accept-Encoding header is missing #9734

Closed
@robin-moser

Description

@robin-moser

Welcome!

  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've searched similar issues on the Traefik community forum and didn't find any.

What did you do?

I enabled content encoding with the new (3.0.0-beta2) compress middleware. When including a request header, for example Accept-Encoding: br, gzip, the content gets encoded properly by the new brotli compression.

When omitting the header, the content unexpectedly gets encoded by brotli, too.

RFC9110 (accept-encoding) states, that "If no Accept-Encoding header field is in the request, any content coding is considered acceptable by the user agent." So technically, the new implementation from traefik is correct. But in practice, this is really uncommon beahviour and could break many applications out there.

The problem with this behaviour is, that tools like curl often don't send any header by default but can't deal with compression by themself. Given a tool with a webui and an api, the use wants the webui to compress the content, but some scripts or cli tools may use the api and fail so because of the compression. So usually, a site doesn't compress the content if no header is present to ensure compatibility.

Examples: (all three sites support brotli compression)

# with the header

curl --silent --output /dev/null --dump-header /dev/stdout  -H 'Accept-Encoding: gzip,br' https://www.google.com | grep encoding
content-encoding: gzip
curl --silent --output /dev/null --dump-header /dev/stdout  -H 'Accept-Encoding: gzip,br' https://www.facebook.com | grep encoding
content-encoding: br
curl --silent --output /dev/null --dump-header /dev/stdout -H 'Accept-Encoding: gzip,br' https://www.docker.com | grep encoding
content-encoding: br
curl --silent --output /dev/null --dump-header /dev/stdout -H 'Accept-Encoding: gzip,br' https://<traefik-v3-with-compress> | grep encoding
content-encoding: br

#now without the header

curl --silent --output /dev/null --dump-header /dev/stdout https://www.google.com | grep encoding
curl --silent --output /dev/null --dump-header /dev/stdout https://www.facebook.com | grep encoding
curl --silent --output /dev/null --dump-header /dev/stdout https://www.docker.com | grep encoding
curl --silent --output /dev/null --dump-header /dev/stdout https://<traefik-v3-with-compress> | grep encoding
content-encoding: br

# this is the stated problem

curl https://<traefik-v3-with-compress>
Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: <FILE>" to save to a file.

I would suggest to omit compression if no Accept-Encoding header is present.

What version of Traefik are you using?

v3.0.0 beta2

What is your environment & configuration?

middlewares.yml

http:
  middlewares:
    compression:
      compress: {}

traefik.yml

entrypoints:
  websecure:
    address: :443
    http:
      middlewares:
        - compression@file

If applicable, please paste the log output in DEBUG level

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions