Skip to content

Commit 0b29652

Browse files
authoredJan 26, 2024
fix(middleware-sdk-s3): do not warn when content-length is 0 (#5733)
* fix(middleware-sdk-s3): do not warn when content-length is 0 * test(middleware-sdk-s3): test content-length 0
1 parent 888155d commit 0b29652

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed
 

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

+18
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ describe("checkContentLengthHeaderMiddleware", () => {
3535
);
3636
});
3737

38+
it("does not warn if uploading a payload of content-length 0", async () => {
39+
const handler = checkContentLengthHeader()(mockNextHandler, {});
40+
41+
await handler({
42+
request: {
43+
method: null,
44+
protocol: null,
45+
hostname: null,
46+
path: null,
47+
query: {},
48+
headers: { "content-length": 0 },
49+
},
50+
input: {},
51+
});
52+
53+
expect(spy).not.toHaveBeenCalled();
54+
});
55+
3856
it("warns with console if logger is the default NoOpLogger", async () => {
3957
const handler = checkContentLengthHeader()(mockNextHandler, {
4058
logger: new NoOpLogger(),

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function checkContentLengthHeader(): FinalizeRequestMiddleware<any, any>
2828
const { request } = args;
2929

3030
if (HttpRequest.isInstance(request)) {
31-
if (!request.headers[CONTENT_LENGTH_HEADER]) {
31+
if (!(CONTENT_LENGTH_HEADER in request.headers)) {
3232
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.`;
3333
if (typeof context?.logger?.warn === "function" && !(context.logger instanceof NoOpLogger)) {
3434
context.logger.warn(message);

0 commit comments

Comments
 (0)
Please sign in to comment.