UNPKG

@aws-amplify/storage

Version:

Storage category of aws-amplify

28 lines (26 loc) 1.17 kB
'use strict'; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 Object.defineProperty(exports, "__esModule", { value: true }); exports.contentSha256Middleware = void 0; const aws_client_utils_1 = require("@aws-amplify/core/internals/aws-client-utils"); const constants_1 = require("./constants"); /** * A middleware that adds the x-amz-content-sha256 header to the request if it is not already present. * It's required for S3 requests in browsers where the request body is sent in 1 chunk. * @see https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html * * @internal */ const contentSha256Middleware = (options) => (next) => async function contentSha256Middleware(request) { if (request.headers[constants_1.CONTENT_SHA256_HEADER]) { return next(request); } else { const hash = await (0, aws_client_utils_1.getHashedPayload)(request.body); request.headers[constants_1.CONTENT_SHA256_HEADER] = hash; return next(request); } }; exports.contentSha256Middleware = contentSha256Middleware; //# sourceMappingURL=contentSha256middleware.js.map