Skip to content

Commit d80a734

Browse files
committed
fix(middleware-flexible-checksums): buffer stream chunks to minimum required size
1 parent 53f15ec commit d80a734

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
HandlerExecutionContext,
1010
MetadataBearer,
1111
} from "@smithy/types";
12+
import { createBufferedReadable } from "@smithy/util-stream";
1213

1314
import { PreviouslyResolved } from "./configuration";
1415
import { ChecksumAlgorithm, DEFAULT_CHECKSUM_ALGORITHM, RequestChecksumCalculation } from "./constants";
@@ -119,7 +120,7 @@ export const flexibleChecksumsMiddleware =
119120
const checksumAlgorithmFn = selectChecksumAlgorithmFunction(checksumAlgorithm, config);
120121
if (isStreaming(requestBody)) {
121122
const { getAwsChunkedEncodingStream, bodyLengthChecker } = config;
122-
updatedBody = getAwsChunkedEncodingStream(requestBody, {
123+
updatedBody = getAwsChunkedEncodingStream(createBufferedReadable(requestBody, 64 * 1024, context.logger), {
123124
base64Encoder,
124125
bodyLengthChecker,
125126
checksumLocationName,

packages/middleware-sdk-s3/src/check-content-length-header.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,24 @@ describe("checkContentLengthHeaderMiddleware", () => {
130130

131131
expect(spy).not.toHaveBeenCalled();
132132
});
133+
134+
it("does not warn if uploading a payload of known length via alternate header x-amz-decoded-content-length", async () => {
135+
const handler = checkContentLengthHeader()(mockNextHandler, {});
136+
137+
await handler({
138+
request: {
139+
method: null,
140+
protocol: null,
141+
hostname: null,
142+
path: null,
143+
query: {},
144+
headers: {
145+
"x-amz-decoded-content-length": "5",
146+
},
147+
},
148+
input: {},
149+
});
150+
151+
expect(spy).not.toHaveBeenCalled();
152+
});
133153
});

packages/middleware-sdk-s3/src/check-content-length-header.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from "@smithy/types";
1313

1414
const CONTENT_LENGTH_HEADER = "content-length";
15+
const DECODED_CONTENT_LENGTH_HEADER = "x-amz-decoded-content-length";
1516

1617
/**
1718
* @internal
@@ -28,7 +29,7 @@ export function checkContentLengthHeader(): FinalizeRequestMiddleware<any, any>
2829
const { request } = args;
2930

3031
if (HttpRequest.isInstance(request)) {
31-
if (!(CONTENT_LENGTH_HEADER in request.headers)) {
32+
if (!(CONTENT_LENGTH_HEADER in request.headers) && !(DECODED_CONTENT_LENGTH_HEADER in request.headers)) {
3233
const message = `Are you using a Stream of unknown length as the Body of a PutObject request? Consider using Upload instead from @aws-sdk/lib-storage.`;
3334
if (typeof context?.logger?.warn === "function" && !(context.logger instanceof NoOpLogger)) {
3435
context.logger.warn(message);

0 commit comments

Comments
 (0)