diff --git a/packages/middleware-flexible-checksums/src/configuration.ts b/packages/middleware-flexible-checksums/src/configuration.ts index e92871b491b5..a6a066c74924 100644 --- a/packages/middleware-flexible-checksums/src/configuration.ts +++ b/packages/middleware-flexible-checksums/src/configuration.ts @@ -4,10 +4,13 @@ import { Encoder, GetAwsChunkedEncodingStream, HashConstructor, + Provider, StreamCollector, StreamHasher, } from "@smithy/types"; +import { RequestChecksumCalculation, ResponseChecksumValidation } from "./constants"; + export interface PreviouslyResolved { /** * The function that will be used to convert binary data to a base64-encoded string. @@ -31,6 +34,16 @@ export interface PreviouslyResolved { */ md5: ChecksumConstructor | HashConstructor; + /** + * Determines when a checksum will be calculated for request payloads + */ + requestChecksumCalculation: Provider; + + /** + * Determines when a checksum will be calculated for response payloads + */ + responseChecksumValidation: Provider; + /** * A constructor for a class implementing the {@link Hash} interface that computes SHA1 hashes. * @internal diff --git a/packages/middleware-flexible-checksums/src/constants.ts b/packages/middleware-flexible-checksums/src/constants.ts index 1a1d13a2efa7..eaa64c32ca39 100644 --- a/packages/middleware-flexible-checksums/src/constants.ts +++ b/packages/middleware-flexible-checksums/src/constants.ts @@ -52,6 +52,9 @@ export const DEFAULT_RESPONSE_CHECKSUM_VALIDATION = RequestChecksumCalculation.W * Checksum Algorithms supported by the SDK. */ export enum ChecksumAlgorithm { + /** + * @deprecated Use {@link ChecksumAlgorithm.CRC32} instead. + */ MD5 = "MD5", CRC32 = "CRC32", CRC32C = "CRC32C", @@ -70,7 +73,7 @@ export enum ChecksumLocation { /** * @internal */ -export const DEFAULT_CHECKSUM_ALGORITHM = ChecksumAlgorithm.MD5; +export const DEFAULT_CHECKSUM_ALGORITHM = ChecksumAlgorithm.CRC32; /** * @internal diff --git a/packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.spec.ts b/packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.spec.ts index 995ae1db5480..bfc5c4085d6a 100644 --- a/packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.spec.ts +++ b/packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.spec.ts @@ -2,7 +2,7 @@ import { HttpRequest } from "@smithy/protocol-http"; import { BuildHandlerArguments } from "@smithy/types"; import { PreviouslyResolved } from "./configuration"; -import { ChecksumAlgorithm } from "./constants"; +import { ChecksumAlgorithm, RequestChecksumCalculation } from "./constants"; import { flexibleChecksumsMiddleware } from "./flexibleChecksumsMiddleware"; import { getChecksumAlgorithmForRequest } from "./getChecksumAlgorithmForRequest"; import { getChecksumLocationName } from "./getChecksumLocationName"; @@ -27,7 +27,9 @@ describe(flexibleChecksumsMiddleware.name, () => { const mockChecksumLocationName = "mock-checksum-location-name"; const mockInput = {}; - const mockConfig = {} as PreviouslyResolved; + const mockConfig = { + requestChecksumCalculation: () => Promise.resolve(RequestChecksumCalculation.WHEN_REQUIRED), + } as PreviouslyResolved; const mockMiddlewareConfig = { input: mockInput, requestChecksumRequired: false }; const mockBody = { body: "mockRequestBody" }; diff --git a/packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.ts b/packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.ts index 5f426f35050c..294b0e7fea8f 100644 --- a/packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.ts +++ b/packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.ts @@ -58,6 +58,7 @@ export const flexibleChecksumsMiddleware = const { request } = args; const { body: requestBody, headers } = request; const { base64Encoder, streamHasher } = config; + const requestChecksumCalculation = await config.requestChecksumCalculation(); const { input, requestChecksumRequired, requestAlgorithmMember } = middlewareConfig; const checksumAlgorithm = getChecksumAlgorithmForRequest( @@ -65,6 +66,7 @@ export const flexibleChecksumsMiddleware = { requestChecksumRequired, requestAlgorithmMember, + requestChecksumCalculation, }, !!context.isS3ExpressBucket ); diff --git a/packages/middleware-flexible-checksums/src/flexibleChecksumsResponseMiddleware.spec.ts b/packages/middleware-flexible-checksums/src/flexibleChecksumsResponseMiddleware.spec.ts index 5dc42ae84836..d2c203dfb792 100644 --- a/packages/middleware-flexible-checksums/src/flexibleChecksumsResponseMiddleware.spec.ts +++ b/packages/middleware-flexible-checksums/src/flexibleChecksumsResponseMiddleware.spec.ts @@ -2,7 +2,7 @@ import { HttpRequest } from "@smithy/protocol-http"; import { DeserializeHandlerArguments } from "@smithy/types"; import { PreviouslyResolved } from "./configuration"; -import { ChecksumAlgorithm } from "./constants"; +import { ChecksumAlgorithm, ResponseChecksumValidation } from "./constants"; import { flexibleChecksumsResponseMiddleware } from "./flexibleChecksumsResponseMiddleware"; import { getChecksumLocationName } from "./getChecksumLocationName"; import { FlexibleChecksumsMiddlewareConfig } from "./getFlexibleChecksumsPlugin"; @@ -23,7 +23,9 @@ describe(flexibleChecksumsResponseMiddleware.name, () => { commandName: "mockCommandName", }; - const mockConfig = {} as PreviouslyResolved; + const mockConfig = { + responseChecksumValidation: () => Promise.resolve(ResponseChecksumValidation.WHEN_REQUIRED), + } as PreviouslyResolved; const mockRequestValidationModeMember = "ChecksumEnabled"; const mockResponseAlgorithms = [ChecksumAlgorithm.CRC32, ChecksumAlgorithm.CRC32C]; const mockMiddlewareConfig = { @@ -59,45 +61,40 @@ describe(flexibleChecksumsResponseMiddleware.name, () => { }); describe("skips", () => { - it("if not an instance of HttpRequest", async () => { - const { isInstance } = HttpRequest; - (isInstance as unknown as jest.Mock).mockReturnValue(false); - const handler = flexibleChecksumsResponseMiddleware(mockConfig, mockMiddlewareConfig)(mockNext, mockContext); + it("if requestValidationModeMember is not defined", async () => { + const mockMwConfig = Object.assign({}, mockMiddlewareConfig) as FlexibleChecksumsMiddlewareConfig; + delete mockMwConfig.requestValidationModeMember; + const handler = flexibleChecksumsResponseMiddleware(mockConfig, mockMwConfig)(mockNext, mockContext); await handler(mockArgs); expect(validateChecksumFromResponse).not.toHaveBeenCalled(); + expect(mockNext).toHaveBeenCalledWith(mockArgs); }); - describe("response checksum", () => { - it("if requestValidationModeMember is not defined", async () => { - const mockMwConfig = Object.assign({}, mockMiddlewareConfig) as FlexibleChecksumsMiddlewareConfig; - delete mockMwConfig.requestValidationModeMember; - const handler = flexibleChecksumsResponseMiddleware(mockConfig, mockMwConfig)(mockNext, mockContext); - await handler(mockArgs); - expect(validateChecksumFromResponse).not.toHaveBeenCalled(); - }); + it("if requestValidationModeMember is not enabled in input", async () => { + const handler = flexibleChecksumsResponseMiddleware(mockConfig, mockMiddlewareConfig)(mockNext, mockContext); - it("if requestValidationModeMember is not enabled in input", async () => { - const handler = flexibleChecksumsResponseMiddleware(mockConfig, mockMiddlewareConfig)(mockNext, mockContext); - await handler({ ...mockArgs, input: {} }); - expect(validateChecksumFromResponse).not.toHaveBeenCalled(); - }); + const mockArgsWithoutEnabled = { ...mockArgs, input: {} }; + await handler(mockArgsWithoutEnabled); + expect(validateChecksumFromResponse).not.toHaveBeenCalled(); + expect(mockNext).toHaveBeenCalledWith(mockArgsWithoutEnabled); + }); - it("if checksum is for S3 whole-object multipart GET", async () => { - (isChecksumWithPartNumber as jest.Mock).mockReturnValue(true); - const handler = flexibleChecksumsResponseMiddleware(mockConfig, mockMiddlewareConfig)(mockNext, { - clientName: "S3Client", - commandName: "GetObjectCommand", - }); - await handler(mockArgs); - expect(isChecksumWithPartNumber).toHaveBeenCalledTimes(1); - expect(isChecksumWithPartNumber).toHaveBeenCalledWith(mockChecksum); - expect(validateChecksumFromResponse).not.toHaveBeenCalled(); + it("if checksum is for S3 whole-object multipart GET", async () => { + (isChecksumWithPartNumber as jest.Mock).mockReturnValue(true); + const handler = flexibleChecksumsResponseMiddleware(mockConfig, mockMiddlewareConfig)(mockNext, { + clientName: "S3Client", + commandName: "GetObjectCommand", }); + await handler(mockArgs); + expect(isChecksumWithPartNumber).toHaveBeenCalledTimes(1); + expect(isChecksumWithPartNumber).toHaveBeenCalledWith(mockChecksum); + expect(validateChecksumFromResponse).not.toHaveBeenCalled(); + expect(mockNext).toHaveBeenCalledWith(mockArgs); }); }); describe("validates checksum from response header", () => { - it("generic case", async () => { + it("if requestValidationModeMember is enabled in input", async () => { const handler = flexibleChecksumsResponseMiddleware(mockConfig, mockMiddlewareConfig)(mockNext, mockContext); await handler(mockArgs); @@ -105,6 +102,25 @@ describe(flexibleChecksumsResponseMiddleware.name, () => { config: mockConfig, responseAlgorithms: mockResponseAlgorithms, }); + expect(mockNext).toHaveBeenCalledWith(mockArgs); + }); + + it(`if requestValidationModeMember is not enabled in input, but responseChecksumValidation returns ${ResponseChecksumValidation.WHEN_SUPPORTED}`, async () => { + const mockConfigWithResponseChecksumValidationSupported = { + ...mockConfig, + responseChecksumValidation: () => Promise.resolve(ResponseChecksumValidation.WHEN_SUPPORTED), + }; + const handler = flexibleChecksumsResponseMiddleware( + mockConfigWithResponseChecksumValidationSupported, + mockMiddlewareConfig + )(mockNext, mockContext); + + await handler({ ...mockArgs, input: {} }); + expect(validateChecksumFromResponse).toHaveBeenCalledWith(mockResult.response, { + config: mockConfigWithResponseChecksumValidationSupported, + responseAlgorithms: mockResponseAlgorithms, + }); + expect(mockNext).toHaveBeenCalledWith(mockArgs); }); it("if checksum is for S3 GET without part number", async () => { @@ -120,6 +136,7 @@ describe(flexibleChecksumsResponseMiddleware.name, () => { config: mockConfig, responseAlgorithms: mockResponseAlgorithms, }); + expect(mockNext).toHaveBeenCalledWith(mockArgs); }); }); }); diff --git a/packages/middleware-flexible-checksums/src/flexibleChecksumsResponseMiddleware.ts b/packages/middleware-flexible-checksums/src/flexibleChecksumsResponseMiddleware.ts index 27735dc5b169..77fd108cdafb 100644 --- a/packages/middleware-flexible-checksums/src/flexibleChecksumsResponseMiddleware.ts +++ b/packages/middleware-flexible-checksums/src/flexibleChecksumsResponseMiddleware.ts @@ -1,16 +1,16 @@ -import { HttpRequest, HttpResponse } from "@smithy/protocol-http"; +import { HttpResponse } from "@smithy/protocol-http"; import { - DeserializeHandler, - DeserializeHandlerArguments, - DeserializeHandlerOutput, - DeserializeMiddleware, HandlerExecutionContext, MetadataBearer, RelativeMiddlewareOptions, + SerializeHandler, + SerializeHandlerArguments, + SerializeHandlerOutput, + SerializeMiddleware, } from "@smithy/types"; import { PreviouslyResolved } from "./configuration"; -import { ChecksumAlgorithm } from "./constants"; +import { ChecksumAlgorithm, ResponseChecksumValidation } from "./constants"; import { getChecksumAlgorithmListForResponse } from "./getChecksumAlgorithmListForResponse"; import { getChecksumLocationName } from "./getChecksumLocationName"; import { isChecksumWithPartNumber } from "./isChecksumWithPartNumber"; @@ -37,8 +37,8 @@ export interface FlexibleChecksumsResponseMiddlewareConfig { */ export const flexibleChecksumsResponseMiddlewareOptions: RelativeMiddlewareOptions = { name: "flexibleChecksumsResponseMiddleware", - toMiddleware: "deserializerMiddleware", - relation: "after", + toMiddleware: "serializerMiddleware", + relation: "before", tags: ["BODY_CHECKSUM"], override: true, }; @@ -52,32 +52,38 @@ export const flexibleChecksumsResponseMiddleware = ( config: PreviouslyResolved, middlewareConfig: FlexibleChecksumsResponseMiddlewareConfig - ): DeserializeMiddleware => + ): SerializeMiddleware => ( - next: DeserializeHandler, + next: SerializeHandler, context: HandlerExecutionContext - ): DeserializeHandler => - async (args: DeserializeHandlerArguments): Promise> => { - if (!HttpRequest.isInstance(args.request)) { - return next(args); + ): SerializeHandler => + async (args: SerializeHandlerArguments): Promise> => { + const input = args.input; + const { requestValidationModeMember, responseAlgorithms } = middlewareConfig; + const responseChecksumValidation = await config.responseChecksumValidation(); + + const isResponseChecksumValidationNeeded = + requestValidationModeMember && + (input[requestValidationModeMember] === "ENABLED" || + responseChecksumValidation === ResponseChecksumValidation.WHEN_SUPPORTED); + + if (isResponseChecksumValidationNeeded) { + input[requestValidationModeMember] = "ENABLED"; } - const input = args.input; const result = await next(args); const response = result.response as HttpResponse; let collectedStream: Uint8Array | undefined = undefined; - const { requestValidationModeMember, responseAlgorithms } = middlewareConfig; - // @ts-ignore Element implicitly has an 'any' type for input[requestValidationModeMember] - if (requestValidationModeMember && input[requestValidationModeMember] === "ENABLED") { + if (isResponseChecksumValidationNeeded) { const { clientName, commandName } = context; const isS3WholeObjectMultipartGetResponseChecksum = clientName === "S3Client" && commandName === "GetObjectCommand" && getChecksumAlgorithmListForResponse(responseAlgorithms).every((algorithm: ChecksumAlgorithm) => { const responseHeader = getChecksumLocationName(algorithm); - const checksumFromResponse = response.headers[responseHeader]; + const checksumFromResponse = response.headers?.[responseHeader]; return !checksumFromResponse || isChecksumWithPartNumber(checksumFromResponse); }); if (isS3WholeObjectMultipartGetResponseChecksum) { diff --git a/packages/middleware-flexible-checksums/src/getChecksumAlgorithmForRequest.spec.ts b/packages/middleware-flexible-checksums/src/getChecksumAlgorithmForRequest.spec.ts index ffefd6efd2b6..5b7998923131 100644 --- a/packages/middleware-flexible-checksums/src/getChecksumAlgorithmForRequest.spec.ts +++ b/packages/middleware-flexible-checksums/src/getChecksumAlgorithmForRequest.spec.ts @@ -1,4 +1,4 @@ -import { ChecksumAlgorithm } from "./constants"; +import { DEFAULT_CHECKSUM_ALGORITHM, RequestChecksumCalculation } from "./constants"; import { getChecksumAlgorithmForRequest } from "./getChecksumAlgorithmForRequest"; import { CLIENT_SUPPORTED_ALGORITHMS } from "./types"; @@ -6,36 +6,88 @@ describe(getChecksumAlgorithmForRequest.name, () => { const mockRequestAlgorithmMember = "mockRequestAlgorithmMember"; describe("when requestAlgorithmMember is not provided", () => { - it("returns MD5 if requestChecksumRequired is set", () => { - expect(getChecksumAlgorithmForRequest({}, { requestChecksumRequired: true })).toEqual(ChecksumAlgorithm.MD5); + describe(`when requestChecksumCalculation is '${RequestChecksumCalculation.WHEN_REQUIRED}'`, () => { + const mockOptions = { requestChecksumCalculation: RequestChecksumCalculation.WHEN_REQUIRED }; + + it(`returns ${DEFAULT_CHECKSUM_ALGORITHM} if requestChecksumRequired is set`, () => { + expect(getChecksumAlgorithmForRequest({}, { ...mockOptions, requestChecksumRequired: true })).toEqual( + DEFAULT_CHECKSUM_ALGORITHM + ); + }); + + it("returns undefined if requestChecksumRequired is false", () => { + expect(getChecksumAlgorithmForRequest({}, { ...mockOptions, requestChecksumRequired: false })).toBeUndefined(); + }); }); - it("returns undefined if requestChecksumRequired is false", () => { - expect(getChecksumAlgorithmForRequest({}, { requestChecksumRequired: false })).toBeUndefined(); + describe(`when requestChecksumCalculation is '${RequestChecksumCalculation.WHEN_SUPPORTED}'`, () => { + const mockOptions = { requestChecksumCalculation: RequestChecksumCalculation.WHEN_SUPPORTED }; + + it(`returns ${DEFAULT_CHECKSUM_ALGORITHM} if requestChecksumRequired is set`, () => { + expect(getChecksumAlgorithmForRequest({}, { ...mockOptions, requestChecksumRequired: true })).toEqual( + DEFAULT_CHECKSUM_ALGORITHM + ); + }); + + it(`returns ${DEFAULT_CHECKSUM_ALGORITHM} if requestChecksumRequired is false`, () => { + expect(getChecksumAlgorithmForRequest({}, { ...mockOptions, requestChecksumRequired: false })).toEqual( + DEFAULT_CHECKSUM_ALGORITHM + ); + }); }); }); describe("when requestAlgorithmMember is not set in input", () => { - const mockOptions = { requestAlgorithmMember: mockRequestAlgorithmMember }; + const mockOptionsWithAlgoMember = { requestAlgorithmMember: mockRequestAlgorithmMember }; - it("returns MD5 if requestChecksumRequired is set", () => { - expect(getChecksumAlgorithmForRequest({}, { ...mockOptions, requestChecksumRequired: true })).toEqual( - ChecksumAlgorithm.MD5 - ); + describe(`when requestChecksumCalculation is '${RequestChecksumCalculation.WHEN_REQUIRED}'`, () => { + const mockOptions = { + ...mockOptionsWithAlgoMember, + requestChecksumCalculation: RequestChecksumCalculation.WHEN_REQUIRED, + }; + + it(`returns ${DEFAULT_CHECKSUM_ALGORITHM} if requestChecksumRequired is set`, () => { + expect(getChecksumAlgorithmForRequest({}, { ...mockOptions, requestChecksumRequired: true })).toEqual( + DEFAULT_CHECKSUM_ALGORITHM + ); + }); + + it("returns undefined if requestChecksumRequired is false", () => { + expect(getChecksumAlgorithmForRequest({}, { ...mockOptions, requestChecksumRequired: false })).toBeUndefined(); + }); }); - it("returns undefined if requestChecksumRequired is false", () => { - expect(getChecksumAlgorithmForRequest({}, { ...mockOptions, requestChecksumRequired: false })).toBeUndefined(); + describe(`when requestChecksumCalculation is '${RequestChecksumCalculation.WHEN_SUPPORTED}'`, () => { + const mockOptions = { + ...mockOptionsWithAlgoMember, + requestChecksumCalculation: RequestChecksumCalculation.WHEN_SUPPORTED, + }; + + it(`returns ${DEFAULT_CHECKSUM_ALGORITHM} if requestChecksumRequired is set`, () => { + expect(getChecksumAlgorithmForRequest({}, { ...mockOptions, requestChecksumRequired: true })).toEqual( + DEFAULT_CHECKSUM_ALGORITHM + ); + }); + + it(`returns ${DEFAULT_CHECKSUM_ALGORITHM} if requestChecksumRequired is false`, () => { + expect(getChecksumAlgorithmForRequest({}, { ...mockOptions, requestChecksumRequired: false })).toEqual( + DEFAULT_CHECKSUM_ALGORITHM + ); + }); }); }); it("throws error if input[requestAlgorithmMember] if not supported by client", () => { const unsupportedAlgo = "unsupportedAlgo"; const mockInput = { [mockRequestAlgorithmMember]: unsupportedAlgo }; - const mockOptions = { requestChecksumRequired: true, requestAlgorithmMember: mockRequestAlgorithmMember }; + const mockOptions = { + requestChecksumRequired: true, + requestAlgorithmMember: mockRequestAlgorithmMember, + requestChecksumCalculation: RequestChecksumCalculation.WHEN_REQUIRED, + }; expect(() => { getChecksumAlgorithmForRequest(mockInput, mockOptions); - }).toThrowError( + }).toThrow( `The checksum algorithm "${unsupportedAlgo}" is not supported by the client.` + ` Select one of ${CLIENT_SUPPORTED_ALGORITHMS}.` ); @@ -44,7 +96,11 @@ describe(getChecksumAlgorithmForRequest.name, () => { describe("returns input[requestAlgorithmMember] if supported by client", () => { it.each(CLIENT_SUPPORTED_ALGORITHMS)("Supported algorithm: %s", (supportedAlgorithm) => { const mockInput = { [mockRequestAlgorithmMember]: supportedAlgorithm }; - const mockOptions = { requestChecksumRequired: true, requestAlgorithmMember: mockRequestAlgorithmMember }; + const mockOptions = { + requestChecksumRequired: true, + requestAlgorithmMember: mockRequestAlgorithmMember, + requestChecksumCalculation: RequestChecksumCalculation.WHEN_REQUIRED, + }; expect(getChecksumAlgorithmForRequest(mockInput, mockOptions)).toEqual(supportedAlgorithm); }); }); diff --git a/packages/middleware-flexible-checksums/src/getChecksumAlgorithmForRequest.ts b/packages/middleware-flexible-checksums/src/getChecksumAlgorithmForRequest.ts index f3cba4b2313f..4834f4acc45a 100644 --- a/packages/middleware-flexible-checksums/src/getChecksumAlgorithmForRequest.ts +++ b/packages/middleware-flexible-checksums/src/getChecksumAlgorithmForRequest.ts @@ -1,4 +1,9 @@ -import { ChecksumAlgorithm, DEFAULT_CHECKSUM_ALGORITHM, S3_EXPRESS_DEFAULT_CHECKSUM_ALGORITHM } from "./constants"; +import { + ChecksumAlgorithm, + DEFAULT_CHECKSUM_ALGORITHM, + RequestChecksumCalculation, + S3_EXPRESS_DEFAULT_CHECKSUM_ALGORITHM, +} from "./constants"; import { CLIENT_SUPPORTED_ALGORITHMS } from "./types"; export interface GetChecksumAlgorithmForRequestOptions { @@ -11,6 +16,11 @@ export interface GetChecksumAlgorithmForRequestOptions { * Defines a top-level operation input member that is used to configure request checksum behavior. */ requestAlgorithmMember?: string; + + /** + * Determines when a checksum will be calculated for request payloads + */ + requestChecksumCalculation: RequestChecksumCalculation; } /** @@ -20,7 +30,11 @@ export interface GetChecksumAlgorithmForRequestOptions { */ export const getChecksumAlgorithmForRequest = ( input: any, - { requestChecksumRequired, requestAlgorithmMember }: GetChecksumAlgorithmForRequestOptions, + { + requestChecksumRequired, + requestAlgorithmMember, + requestChecksumCalculation, + }: GetChecksumAlgorithmForRequestOptions, isS3Express?: boolean ): ChecksumAlgorithm | undefined => { const defaultAlgorithm = isS3Express ? S3_EXPRESS_DEFAULT_CHECKSUM_ALGORITHM : DEFAULT_CHECKSUM_ALGORITHM; @@ -28,8 +42,11 @@ export const getChecksumAlgorithmForRequest = ( // Either the Operation input member that is used to configure request checksum behavior is not set, or // the value for input member to configure flexible checksum is not set. if (!requestAlgorithmMember || !input[requestAlgorithmMember]) { - // Select an algorithm only if request checksum is required. - return requestChecksumRequired ? defaultAlgorithm : undefined; + // Select an algorithm only if request checksum calculation is supported + // or request checksum is required. + return requestChecksumCalculation === RequestChecksumCalculation.WHEN_SUPPORTED || requestChecksumRequired + ? defaultAlgorithm + : undefined; } const checksumAlgorithm = input[requestAlgorithmMember]; diff --git a/private/aws-middleware-test/src/middleware-serde.spec.ts b/private/aws-middleware-test/src/middleware-serde.spec.ts index 88f476cf556a..7c7ad433d698 100644 --- a/private/aws-middleware-test/src/middleware-serde.spec.ts +++ b/private/aws-middleware-test/src/middleware-serde.spec.ts @@ -20,7 +20,7 @@ describe("middleware-serde", () => { "x-amz-acl": "private", "content-length": "509", Expect: "100-continue", - "content-md5": "qpwmS0vhCISEXes008aoXA==", + "x-amz-checksum-crc32": "XnKFaw==", host: "s3.us-west-2.amazonaws.com", "x-amz-content-sha256": "c0a89780e1aac5dfa17604e9e25616e7babba0b655db189be49b4c352543bb22", },