diff --git a/src/generateS3Client.ts b/src/generateS3Client.ts index 96f7661..e2aaf32 100644 --- a/src/generateS3Client.ts +++ b/src/generateS3Client.ts @@ -42,6 +42,8 @@ export function generateS3Client({ maxAttempts: RETRY_ATTEMPTS, requestHandler: oneBlinkRequestHandler, credentials: {} as AwsCredentialIdentity, + requestChecksumCalculation: + oneBlinkHttpHandler.requestChecksumCalculation, // Sign requests with our own Authorization header instead // of letting AWS SDK attempt to generate credentials signer: { diff --git a/src/http-handlers/FetchHandler.ts b/src/http-handlers/FetchHandler.ts index 0dd979b..9955b37 100644 --- a/src/http-handlers/FetchHandler.ts +++ b/src/http-handlers/FetchHandler.ts @@ -2,8 +2,11 @@ import { HttpRequest, HttpResponse } from '@smithy/protocol-http' import { HttpHandlerOptions } from '@smithy/types' import { IOneBlinkHttpHandler } from './types.js' import { GetObjectCommandOutput } from '@aws-sdk/client-s3' +import { RequestChecksumCalculation } from '@aws-sdk/middleware-flexible-checksums' export class OneBlinkFetchHandler implements IOneBlinkHttpHandler { + requestChecksumCalculation = RequestChecksumCalculation.WHEN_REQUIRED + async handleRequest(request: HttpRequest, options?: HttpHandlerOptions) { const { FetchHttpHandler } = await import('@smithy/fetch-http-handler') const fetchHttpHandler = new FetchHttpHandler() diff --git a/src/http-handlers/NodeJsHandler.ts b/src/http-handlers/NodeJsHandler.ts index 8941a93..0baa24a 100644 --- a/src/http-handlers/NodeJsHandler.ts +++ b/src/http-handlers/NodeJsHandler.ts @@ -2,8 +2,11 @@ import { HttpRequest, HttpResponse } from '@smithy/protocol-http' import { HttpHandlerOptions } from '@smithy/types' import { IOneBlinkHttpHandler, FailResponse } from './types.js' import { GetObjectCommandOutput } from '@aws-sdk/client-s3' +import { RequestChecksumCalculation } from '@aws-sdk/middleware-flexible-checksums' export class OneBlinkNodeJsHandler implements IOneBlinkHttpHandler { + requestChecksumCalculation = RequestChecksumCalculation.WHEN_SUPPORTED + async handleRequest( request: HttpRequest, options?: HttpHandlerOptions | undefined, diff --git a/src/http-handlers/types.ts b/src/http-handlers/types.ts index b8bcf36..a415bee 100644 --- a/src/http-handlers/types.ts +++ b/src/http-handlers/types.ts @@ -1,4 +1,5 @@ import { GetObjectCommandOutput } from '@aws-sdk/client-s3' +import { RequestChecksumCalculation } from '@aws-sdk/middleware-flexible-checksums' import { AWSTypes } from '@oneblink/types' import { HttpRequest, HttpResponse } from '@smithy/protocol-http' import { HttpHandlerOptions } from '@smithy/types' @@ -14,6 +15,11 @@ export type FailResponse = { } export interface IOneBlinkHttpHandler { + /** + * Need this to avoid this [issue with the AWS + * SDK](https://github.com/aws/aws-sdk-js-v3/issues/6810) + */ + requestChecksumCalculation: RequestChecksumCalculation handleRequest: ( request: HttpRequest, options?: HttpHandlerOptions,