Skip to content

Commit

Permalink
fix(middleware-sdk-s3): do not warn when content-length is 0 (#5733)
Browse files Browse the repository at this point in the history
* fix(middleware-sdk-s3): do not warn when content-length is 0

* test(middleware-sdk-s3): test content-length 0
  • Loading branch information
kuhe authored Jan 26, 2024
1 parent 888155d commit 0b29652
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions packages/middleware-sdk-s3/src/check-content-length-header.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ describe("checkContentLengthHeaderMiddleware", () => {
);
});

it("does not warn if uploading a payload of content-length 0", async () => {
const handler = checkContentLengthHeader()(mockNextHandler, {});

await handler({
request: {
method: null,
protocol: null,
hostname: null,
path: null,
query: {},
headers: { "content-length": 0 },
},
input: {},
});

expect(spy).not.toHaveBeenCalled();
});

it("warns with console if logger is the default NoOpLogger", async () => {
const handler = checkContentLengthHeader()(mockNextHandler, {
logger: new NoOpLogger(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function checkContentLengthHeader(): FinalizeRequestMiddleware<any, any>
const { request } = args;

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

0 comments on commit 0b29652

Please sign in to comment.