Skip to content

Commit dbbe928

Browse files
committed
chore: remove check for request headers from flexibleChecksumsInputMiddleware
This is because the request is not available pre-serialization. This reverts commit 969be81.
1 parent 4279e44 commit dbbe928

File tree

2 files changed

+14
-44
lines changed

2 files changed

+14
-44
lines changed

packages/middleware-flexible-checksums/src/flexibleChecksumsInputMiddleware.spec.ts

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { setFeature } from "@aws-sdk/core";
2-
import { afterEach, beforeEach, describe, expect, test as it, vi } from "vitest";
2+
import { afterEach, describe, expect, test as it, vi } from "vitest";
33

44
import { PreviouslyResolved } from "./configuration";
55
import { DEFAULT_CHECKSUM_ALGORITHM, RequestChecksumCalculation, ResponseChecksumValidation } from "./constants";
66
import { flexibleChecksumsInputMiddleware } from "./flexibleChecksumsInputMiddleware";
7-
import { hasHeaderWithPrefix } from "./hasHeaderWithPrefix";
87

98
vi.mock("@aws-sdk/core");
10-
vi.mock("./hasHeaderWithPrefix");
119

1210
describe(flexibleChecksumsInputMiddleware.name, () => {
1311
const mockNext = vi.fn();
@@ -21,10 +19,6 @@ describe(flexibleChecksumsInputMiddleware.name, () => {
2119
responseChecksumValidation: () => Promise.resolve(ResponseChecksumValidation.WHEN_SUPPORTED),
2220
} as PreviouslyResolved;
2321

24-
beforeEach(() => {
25-
vi.mocked(hasHeaderWithPrefix).mockReturnValue(false);
26-
});
27-
2822
afterEach(() => {
2923
expect(mockNext).toHaveBeenCalledTimes(1);
3024
vi.clearAllMocks();
@@ -42,11 +36,8 @@ describe(flexibleChecksumsInputMiddleware.name, () => {
4236
mockNext,
4337
{}
4438
);
45-
await handler({ input: {}, request: {} });
46-
expect(mockNext).toHaveBeenCalledWith({
47-
input: { [mockRequestAlgorithmMember]: DEFAULT_CHECKSUM_ALGORITHM },
48-
request: {},
49-
});
39+
await handler({ input: {} });
40+
expect(mockNext).toHaveBeenCalledWith({ input: { [mockRequestAlgorithmMember]: DEFAULT_CHECKSUM_ALGORITHM } });
5041
});
5142

5243
it("requestChecksumRequired is set to true", async () => {
@@ -60,11 +51,8 @@ describe(flexibleChecksumsInputMiddleware.name, () => {
6051
requestChecksumRequired: true,
6152
})(mockNext, {});
6253

63-
await handler({ input: {}, request: {} });
64-
expect(mockNext).toHaveBeenCalledWith({
65-
input: { [mockRequestAlgorithmMember]: DEFAULT_CHECKSUM_ALGORITHM },
66-
request: {},
67-
});
54+
await handler({ input: {} });
55+
expect(mockNext).toHaveBeenCalledWith({ input: { [mockRequestAlgorithmMember]: DEFAULT_CHECKSUM_ALGORITHM } });
6856
});
6957
});
7058
});
@@ -94,21 +82,8 @@ describe(flexibleChecksumsInputMiddleware.name, () => {
9482
mockConfigReqChecksumCalculationWhenRequired,
9583
mockMiddlewareConfigWithRequestAlgorithmMember
9684
)(mockNext, {});
97-
await handler({ input: {}, request: {} });
98-
expect(mockNext).toHaveBeenCalledWith({ input: {}, request: {} });
99-
});
100-
101-
it("if checksum header is set", async () => {
102-
const mockArgs = { input: {}, request: { key: "value" } };
103-
vi.mocked(hasHeaderWithPrefix).mockReturnValue(true);
104-
105-
const handler = flexibleChecksumsInputMiddleware(mockConfig, {
106-
...mockMiddlewareConfigWithRequestAlgorithmMember,
107-
requestChecksumRequired: true,
108-
})(mockNext, {});
109-
110-
await handler(mockArgs);
111-
expect(mockNext).toHaveBeenCalledWith(mockArgs);
85+
await handler({ input: {} });
86+
expect(mockNext).toHaveBeenCalledWith({ input: {} });
11287
});
11388
});
11489

@@ -122,13 +97,13 @@ describe(flexibleChecksumsInputMiddleware.name, () => {
12297
mockConfig,
12398
mockMiddlewareConfigWithMockRequestValidationModeMember
12499
)(mockNext, {});
125-
await handler({ input: {}, request: {} });
126-
expect(mockNext).toHaveBeenCalledWith({ input: { [mockRequestValidationModeMember]: "ENABLED" }, request: {} });
100+
await handler({ input: {} });
101+
expect(mockNext).toHaveBeenCalledWith({ input: { [mockRequestValidationModeMember]: "ENABLED" } });
127102
});
128103
});
129104

130105
describe("leaves input.requestValidationModeMember", () => {
131-
const mockArgs = { input: {}, request: {} };
106+
const mockArgs = { input: {} };
132107

133108
it("when requestValidationModeMember is not defined", async () => {
134109
const handler = flexibleChecksumsInputMiddleware(mockConfig, mockMiddlewareConfig)(mockNext, {});
@@ -182,7 +157,7 @@ describe(flexibleChecksumsInputMiddleware.name, () => {
182157
} as PreviouslyResolved;
183158

184159
const handler = flexibleChecksumsInputMiddleware(mockConfigOverride, mockMiddlewareConfig)(mockNext, {});
185-
await handler({ input: {}, request: {} });
160+
await handler({ input: {} });
186161

187162
expect(setFeature).toHaveBeenCalledTimes(2);
188163
if (configKey === "requestChecksumCalculation") {

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { setFeature } from "@aws-sdk/core";
2-
import { HttpRequest } from "@smithy/protocol-http";
32
import {
43
HandlerExecutionContext,
54
MetadataBearer,
@@ -12,7 +11,6 @@ import {
1211

1312
import { PreviouslyResolved } from "./configuration";
1413
import { DEFAULT_CHECKSUM_ALGORITHM, RequestChecksumCalculation, ResponseChecksumValidation } from "./constants";
15-
import { hasHeaderWithPrefix } from "./hasHeaderWithPrefix";
1614

1715
export interface FlexibleChecksumsInputMiddlewareConfig {
1816
/**
@@ -84,13 +82,10 @@ export const flexibleChecksumsInputMiddleware =
8482

8583
// The value for input member to configure flexible checksum is not set.
8684
if (requestAlgorithmMember && !input[requestAlgorithmMember]) {
87-
// Set requestAlgorithmMember as default checksum algorithm only if request checksum algorithm is not supported,
88-
// and either request checksumcalculation is supported or request checksum is required.
85+
// Set requestAlgorithmMember as default checksum algorithm only if request checksum calculation is supported
86+
// or request checksum is required.
8987
if (requestChecksumCalculation === RequestChecksumCalculation.WHEN_SUPPORTED || requestChecksumRequired) {
90-
const request = args.request as HttpRequest;
91-
if (!request.headers || hasHeaderWithPrefix("x-amz-checksum-", request.headers)) {
92-
input[requestAlgorithmMember] = DEFAULT_CHECKSUM_ALGORITHM;
93-
}
88+
input[requestAlgorithmMember] = DEFAULT_CHECKSUM_ALGORITHM;
9489
}
9590
}
9691

0 commit comments

Comments
 (0)