UNPKG

@aws-amplify/storage

Version:

Storage category of aws-amplify

1 lines 1.54 kB
{"version":3,"file":"contentSha256middleware.mjs","sources":["../../../../../../../src/providers/s3/utils/client/runtime/contentSha256middleware.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { getHashedPayload, } from '@aws-amplify/core/internals/aws-client-utils';\nimport { CONTENT_SHA256_HEADER } from './constants';\n/**\n * A middleware that adds the x-amz-content-sha256 header to the request if it is not already present.\n * It's required for S3 requests in browsers where the request body is sent in 1 chunk.\n * @see https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html\n *\n * @internal\n */\nexport const contentSha256MiddlewareFactory = () => (next) => async function contentSha256Middleware(request) {\n if (request.headers[CONTENT_SHA256_HEADER]) {\n return next(request);\n }\n else {\n const hash = await getHashedPayload(request.body);\n request.headers[CONTENT_SHA256_HEADER] = hash;\n return next(request);\n }\n};\n"],"names":[],"mappings":";;;AAAA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,8BAA8B,GAAG,MAAM,CAAC,IAAI,KAAK,eAAe,uBAAuB,CAAC,OAAO,EAAE;AAC9G,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,qBAAqB,CAAC,EAAE;AAChD,QAAQ,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;AAC7B,KAAK;AACL,SAAS;AACT,QAAQ,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC1D,QAAQ,OAAO,CAAC,OAAO,CAAC,qBAAqB,CAAC,GAAG,IAAI,CAAC;AACtD,QAAQ,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;AAC7B,KAAK;AACL;;;;"}