workerd
workerd copied to clipboard
🐛 BUG: Brotli response not decoded
Which Cloudflare product(s) does this pertain to?
Miniflare
What version(s) of the tool(s) are you using?
^3.20231218.4
What version of Node are you using?
18.19.0
What operating system are you using?
Mac
Describe the Bug
The result of res.text()
of a response with content-encoding: br
is not decoded, but when it is gzip
, it is correctly decoded.
This worker returns a mess:
export default {
async fetch() {
const res = await fetch("https://blog.cloudflare.com/this-is-brotli-from-origin", {
headers: {
"accept-encoding": "br, gzip, deflate"
}
});
return new Response(await res.text(), {
headers: {
"content-type": "text/html"
}
});
}
}
This worker returns the correct HTML:
export default {
async fetch() {
const res = await fetch("https://blog.cloudflare.com/this-is-brotli-from-origin", {
headers: {
"accept-encoding": "gzip, deflate"
}
});
return new Response(await res.text(), {
headers: {
"content-type": "text/html"
}
});
}
}
Please provide a link to a minimal reproduction
No response
Please provide any relevant error logs
No response
This is more of a feature request than a bug. The spec does not require brotli support.
That said, we actually do have this support, but it is still experimental. You can enable brotli support by setting the brotli_content_encoding
compatibilty flag. Note this flag is not yet documented nor enabled by default as I think there are some obscure bad interactions with other parts of Cloudfare's stack that we were waiting on fixes to. But you can try it, and if it works in your use case, it works.
@fhanau may know more about what the remaining issues are.
This is more of a feature request than a bug. The spec does not require brotli support.
That said, we actually do have this support, but it is still experimental. You can enable brotli support by setting the
brotli_content_encoding
compatibilty flag. Note this flag is not yet documented nor enabled by default as I think there are some obscure bad interactions with other parts of Cloudfare's stack that we were waiting on fixes to. But you can try it, and if it works in your use case, it works.@fhanau may know more about what the remaining issues are.
Yes, that's a good description of the issue. As Kenton noted, you may experience different behavior in the production runtime than in local testing due to incomplete brotli support Cloudfare's stack. Notably, you will not be able to fetch using the brotli content encoding in production even when you add it to accept-encoding at this time, so currently the flag is still experimental and primarily useful for local testing.
@fhanau ... I wonder if it would be worthwhile adding a warning when br
is specified without the flag / or in production. I know that warnings often go unnoticed so it's of limited value, but while we're waiting for the production stack issues to be resolved it's something.