Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(middleware-sdk-s3): use console warn if logger is no-op #5222

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/middleware-sdk-s3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@aws-sdk/types": "*",
"@aws-sdk/util-arn-parser": "*",
"@smithy/protocol-http": "^3.0.3",
"@smithy/smithy-client": "^2.1.4",
"@smithy/types": "^2.3.1",
"tslib": "^2.5.0"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { NoOpLogger } from "@smithy/smithy-client";

import { checkContentLengthHeader } from "./check-content-length-header";

describe("checkContentLengthHeaderMiddleware", () => {
Expand Down Expand Up @@ -33,6 +35,28 @@ describe("checkContentLengthHeaderMiddleware", () => {
);
});

it("warns with console if logger is the default NoOpLogger", async () => {
const handler = checkContentLengthHeader()(mockNextHandler, {
logger: new NoOpLogger(),
});

await handler({
request: {
method: null,
protocol: null,
hostname: null,
path: null,
query: {},
headers: {},
},
input: {},
});

expect(spy).toHaveBeenCalledWith(
"Are you using a Stream of unknown length as the Body of a PutObject request? Consider using Upload instead from @aws-sdk/lib-storage."
);
});

it("uses the context logger if available", async () => {
const context = {
logger: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { HttpRequest } from "@smithy/protocol-http";
import { NoOpLogger } from "@smithy/smithy-client";
import {
FinalizeHandler,
FinalizeHandlerArguments,
Expand Down Expand Up @@ -29,7 +30,7 @@ export function checkContentLengthHeader(): FinalizeRequestMiddleware<any, any>
if (HttpRequest.isInstance(request)) {
if (!request.headers[CONTENT_LENGTH_HEADER]) {
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") {
if (typeof context?.logger?.warn === "function" && !(context.logger instanceof NoOpLogger)) {
context.logger.warn(message);
} else {
console.warn(message);
Expand Down