traefik: compress midddleware: dont encode content if Accept-Encoding header is missing
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
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 16 (3 by maintainers)
Commits related to this issue
- Do not encode requests if no Acccept-Encoding header is present To ensure compatibility, it is recommended not to compress a request when there is no Accept-Encoding header. See https://github.com/tr... — committed to robin-moser/traefik by robin-moser 3 years ago
- Do not encode requests if no Acccept-Encoding header is present To ensure compatibility, it is recommended not to compress a request when there is no Accept-Encoding header. See https://github.com/tr... — committed to robin-moser/traefik by robin-moser 3 years ago
- Disable br compression when no Accept-Encoding is present As this behavior, while compliant with https://www.rfc-editor.org/rfc/rfc9110.html#section-12.5.3, breaks several clients (like curl or yum/d... — committed to dani/traefik by dani 3 years ago
- Do not encode requests if no Acccept-Encoding header is present To ensure compatibility, it is recommended not to compress a request when there is no Accept-Encoding header. See https://github.com/tr... — committed to robin-moser/traefik by robin-moser 3 years ago
- Do not encode requests if no Acccept-Encoding header is present To ensure compatibility, it is recommended not to compress a request when there is no Accept-Encoding header. See https://github.com/tr... — committed to robin-moser/traefik by robin-moser 3 years ago
- Do not encode requests if no Acccept-Encoding header is present To ensure compatibility, it is recommended not to compress a request when there is no Accept-Encoding header. See https://github.com/tr... — committed to robin-moser/traefik by robin-moser 3 years ago
- Do not encode requests if no Acccept-Encoding header is present To ensure compatibility, it is recommended not to compress a request when there is no Accept-Encoding header. See https://github.com/tr... — committed to robin-moser/traefik by robin-moser 3 years ago
- Do not encode requests if no Acccept-Encoding header is present To ensure compatibility, it is recommended not to compress a request when there is no Accept-Encoding header. See https://github.com/tr... — committed to robin-moser/traefik by robin-moser 3 years ago
- Do not encode requests if no Acccept-Encoding header is present To ensure compatibility, it is recommended not to compress a request when there is no Accept-Encoding header. See https://github.com/tr... — committed to robin-moser/traefik by robin-moser 3 years ago
Indeed it’s fixed. This issue should be closed