aws / aws-lambda-nodejs-runtime-interface-client

Apache License 2.0
177 stars 57 forks source link

Function URL with Response Streaming does not support Content-Encoding #96

Open paya-cz opened 5 months ago

paya-cz commented 5 months ago

If I compress my response using gzip and set a proper Content-Encoding response header, it appears like Function URL will decompress my response on-the-fly, remove the Content-Encoding header, and pass down the uncompressed response stream. This is wasteful and unnecessary.

const pipeline = require("util").promisify(require("stream").pipeline);
const { Readable } = require("stream");
const zlib = require('zlib');

exports.handler = awslambda.streamifyResponse(async (event,
responseStream, context) => {
    responseStream = awslambda.HttpResponseStream.from(responseStream, {
      statusCode: 200,
      headers: {
       'content-encoding': 'gzip',
       'content-type': 'text/plain',
      }
    });

    await pipeline(
      Readable.from(zlib.gzipSync('hello world')),
      responseStream,
    );
});

See here - the response is uncompressed, with Content-Encoding header stripped:

ss