Skip to content

S3 PutObject with gzip stream not working with the integrity change - content length required for non-file data streams #7434

@ohana54

Description

@ohana54

Checkboxes for prior research

Describe the bug

Hi,

I encountered the following bug after upgrading the sdk to the latest version (from a very old version).
When using S3 PutObject with a file read stream piped to a gzip stream, I get an error:

TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "x-amz-decoded-content-length"

Regression Issue

  • Select this option if this issue appears to be a regression.

SDK version number

@aws-sdk/[email protected]

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

Node.js v24.5.0

Reproduction Steps

import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
import * as fs from "node:fs";
import * as path from "node:path";
import * as zlib from "node:zlib";

const s3 = new S3Client();
const body = fs.createReadStream('path-to-file')
  .pipe(zlib.createGzip());

s3.send(
  new PutObjectCommand({
    Bucket: 'bucket',
    Key: 'key',
    Body: body,
  })
);

Observed Behavior

An error was encountered in a non-retryable streaming request.
node:_http_outgoing:645
  validateHeaderValue(name, value);
  ^

TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "x-amz-decoded-content-length"
    at ClientRequest.setHeader (node:_http_outgoing:645:3)
    at new ClientRequest (node:_http_client:354:14)
    at request (node:http:102:10)
    at /Users/***/test-s3-client/node_modules/@smithy/node-http-handler/dist-cjs/index.js:324:25
    at new Promise (<anonymous>)
    at NodeHttpHandler.handle (/Users/***/test-s3-client/node_modules/@smithy/node-http-handler/dist-cjs/index.js:265:16)
    at async /Users/***/test-s3-client/node_modules/@aws-sdk/middleware-flexible-checksums/dist-cjs/index.js:372:20
    at async /Users/***/test-s3-client/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:422:20
    at async /Users/***/test-s3-client/node_modules/@smithy/middleware-serde/dist-cjs/index.js:6:26 {
  code: 'ERR_HTTP_INVALID_HEADER_VALUE'
}

Expected Behavior

No error, request succeeds

Possible Solution

No response

Additional Information/Context

I traced it to the checksum middleware which is now active due to the default integrity change.
The checksum middleware is putting this header, which is undefined because the content-length middleware can't calculate the size of the gzip stream.

Is it correct to assume I need to disable checksum calculation as it's not possible for the sdk to do it without content length?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.potential-regressionMarking this issue as a potential regression to be checked by team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions