Transfer-Encoding header being ignored by Cloudflare Workers

I’m trying to generate chunked gzip response with Cloudflare Workers but it seems the “Transfer-Encoding” is simply being ignored, EVEN IF 'Cache-Control': 'no-transform' header is used. Here’s the code:

const bytes = new Uint8Array([0x00, 0x00, 0x13, 0x0d, 0x0a, 0x31, 0x36, 0x0d, 0x0a, 0xf3, 0x48, 0xcd, 0xc9, 0xc9, 0x57, 0x08, 0xcf, 0x2f, 0xca, 0x49, 0x51, 0x04, 0x00, 0xa3, 0x1c, 0x29, 0x1c, 0x0c, 0x00, 0x00, 0x00, 0x0d, 0x0a, 0x30, 0x0d, 0x0a, 0x0d, 0x0a])

addEventListener('fetch', event => {
  event.respondWith(new Response(bytes, {
    headers: {
      'Cache-Control': 'no-transform',
      'Content-Encoding': 'gzip',
      'Transfer-Encoding': 'chunked'

This worker should generate “Hello world” gzip response, but because Cloudflare decides to skip Transfer-Encoding header it doesn’t work.

How to create response (or more specifically streaming response), with Transfer-Encoding being properly set? Currently it’s impossible to generate any compressed response by Cloudflare. It limits its uses very much unfortunately.

Could you provide an example of Cloudflare Worker that returns generated and chunked gzip response? How to ensure Transfer-Encoding is set properly?

1 Like