Why does Content-Encoding become none in functions stream and functions 2.0?

I want to use gzip and used 4 methods, only the first one convert to base64 works. But I want to use functions 2.0

  1. base64
import { gzipSync } from 'zlib'
  
export const handler = async () => {
  return {
    statusCode: 200,
    headers: { 'Content-Encoding': 'gzip' },
    body: gzipSync('Hello World').toString('base64'),
    isBase64Encoded: true,
  }
}
Content-Encoding: gzip
...
Hello World
  1. stream
import { stream } from "@netlify/functions"
import { gzipSync } from 'zlib'

export const handler = stream(async () => {
  return {
    statusCode: 200,
    headers: { 'Content-Encoding': 'gzip' },
    body: new ReadableStream({
      start(controller) {
        controller.enqueue(gzipSync('Hello World'))
        controller.close()
      }
    }),
  }
})
Content-Encoding: none
...
‹������óHÍÉÉWÏ/ÊI�V±J���
  1. functions 2.0
import { gzipSync } from 'zlib'

export default async () => {
  return new Response(gzipSync('Hello World'), {
    headers: { 'Content-Encoding': 'gzip' },
  })
}
Content-Encoding: none
...
‹������óHÍÉÉWÏ/ÊI�V±J���
  1. functions 2.0 stream
import { gzipSync } from 'zlib'

export default async () => {
  return new Response(new ReadableStream({
    start(controller) {
      controller.enqueue(gzipSync('Hello World'))
      controller.close()
    }
  }), {
    headers: { 'Content-Encoding': 'gzip' },
  })
}
Content-Encoding: none
...
‹������óHÍÉÉWÏ/ÊI�V±J���

This is currently a bug and already being looked into.

1 Like

This should now be fixed.

1 Like