Serve pre-compressed brotli content

We are trying to serve pre-compressed brotli content from R2 through a worker to the clients.

The basic idea is that:

  • If the client supports brotli, serve the content as is
  • If the client doesn’t support brotli, make use of the transparent re/de-compression of the edge and serve either as gzip or plain text.

This is already working fine with gzip pre-compressed content:

  • The response headers in the worker set: ‘Content-Type’:‘text/plain’ and ‘Content-Encoding’:‘gzip’
  • The response is passed on as-is: encodeBody: ‘manual’

However, switching to brotli compression (and changing the ‘Content-Encoding’ header accordingly to ‘br’) does not work as expected: The response is always the binary brotli-compressed data, irrespective of the accept encoding of the client.

What are we missing? Any ideas would be very welcome.