@aws-sdk/middleware-flexible-checksums 3.713.0 → 3.715.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist-cjs/index.js CHANGED
@@ -169,6 +169,17 @@ var hasHeader = /* @__PURE__ */ __name((header, headers) => {
169
169
  return false;
170
170
  }, "hasHeader");
171
171
 
172
+ // src/hasHeaderWithPrefix.ts
173
+ var hasHeaderWithPrefix = /* @__PURE__ */ __name((headerPrefix, headers) => {
174
+ const soughtHeaderPrefix = headerPrefix.toLowerCase();
175
+ for (const headerName of Object.keys(headers)) {
176
+ if (headerName.toLowerCase().startsWith(soughtHeaderPrefix)) {
177
+ return true;
178
+ }
179
+ }
180
+ return false;
181
+ }, "hasHeaderWithPrefix");
182
+
172
183
  // src/isStreaming.ts
173
184
  var import_is_array_buffer = require("@smithy/is-array-buffer");
174
185
  var isStreaming = /* @__PURE__ */ __name((body) => body !== void 0 && typeof body !== "string" && !ArrayBuffer.isView(body) && !(0, import_is_array_buffer.isArrayBuffer)(body), "isStreaming");
@@ -176,13 +187,22 @@ var isStreaming = /* @__PURE__ */ __name((body) => body !== void 0 && typeof bod
176
187
  // src/selectChecksumAlgorithmFunction.ts
177
188
  var import_crc32c = require("@aws-crypto/crc32c");
178
189
  var import_getCrc32ChecksumAlgorithmFunction = require("././getCrc32ChecksumAlgorithmFunction");
179
- var selectChecksumAlgorithmFunction = /* @__PURE__ */ __name((checksumAlgorithm, config) => ({
180
- ["MD5" /* MD5 */]: config.md5,
181
- ["CRC32" /* CRC32 */]: (0, import_getCrc32ChecksumAlgorithmFunction.getCrc32ChecksumAlgorithmFunction)(),
182
- ["CRC32C" /* CRC32C */]: import_crc32c.AwsCrc32c,
183
- ["SHA1" /* SHA1 */]: config.sha1,
184
- ["SHA256" /* SHA256 */]: config.sha256
185
- })[checksumAlgorithm], "selectChecksumAlgorithmFunction");
190
+ var selectChecksumAlgorithmFunction = /* @__PURE__ */ __name((checksumAlgorithm, config) => {
191
+ switch (checksumAlgorithm) {
192
+ case "MD5" /* MD5 */:
193
+ return config.md5;
194
+ case "CRC32" /* CRC32 */:
195
+ return (0, import_getCrc32ChecksumAlgorithmFunction.getCrc32ChecksumAlgorithmFunction)();
196
+ case "CRC32C" /* CRC32C */:
197
+ return import_crc32c.AwsCrc32c;
198
+ case "SHA1" /* SHA1 */:
199
+ return config.sha1;
200
+ case "SHA256" /* SHA256 */:
201
+ return config.sha256;
202
+ default:
203
+ throw new Error(`Unsupported checksum algorithm: ${checksumAlgorithm}`);
204
+ }
205
+ }, "selectChecksumAlgorithmFunction");
186
206
 
187
207
  // src/stringHasher.ts
188
208
  var import_util_utf8 = require("@smithy/util-utf8");
@@ -203,6 +223,9 @@ var flexibleChecksumsMiddleware = /* @__PURE__ */ __name((config, middlewareConf
203
223
  if (!import_protocol_http.HttpRequest.isInstance(args.request)) {
204
224
  return next(args);
205
225
  }
226
+ if (hasHeaderWithPrefix("x-amz-checksum-", args.request.headers)) {
227
+ return next(args);
228
+ }
206
229
  const { request, input } = args;
207
230
  const { body: requestBody, headers } = request;
208
231
  const { base64Encoder, streamHasher } = config;
@@ -211,7 +234,7 @@ var flexibleChecksumsMiddleware = /* @__PURE__ */ __name((config, middlewareConf
211
234
  input,
212
235
  {
213
236
  requestChecksumRequired,
214
- requestAlgorithmMember
237
+ requestAlgorithmMember: requestAlgorithmMember == null ? void 0 : requestAlgorithmMember.name
215
238
  },
216
239
  !!context.isS3ExpressBucket
217
240
  );
@@ -4,6 +4,7 @@ import { ChecksumAlgorithm } from "./constants";
4
4
  import { getChecksumAlgorithmForRequest } from "./getChecksumAlgorithmForRequest";
5
5
  import { getChecksumLocationName } from "./getChecksumLocationName";
6
6
  import { hasHeader } from "./hasHeader";
7
+ import { hasHeaderWithPrefix } from "./hasHeaderWithPrefix";
7
8
  import { isStreaming } from "./isStreaming";
8
9
  import { selectChecksumAlgorithmFunction } from "./selectChecksumAlgorithmFunction";
9
10
  import { stringHasher } from "./stringHasher";
@@ -17,13 +18,16 @@ export const flexibleChecksumsMiddleware = (config, middlewareConfig) => (next,
17
18
  if (!HttpRequest.isInstance(args.request)) {
18
19
  return next(args);
19
20
  }
21
+ if (hasHeaderWithPrefix("x-amz-checksum-", args.request.headers)) {
22
+ return next(args);
23
+ }
20
24
  const { request, input } = args;
21
25
  const { body: requestBody, headers } = request;
22
26
  const { base64Encoder, streamHasher } = config;
23
27
  const { requestChecksumRequired, requestAlgorithmMember } = middlewareConfig;
24
28
  const checksumAlgorithm = getChecksumAlgorithmForRequest(input, {
25
29
  requestChecksumRequired,
26
- requestAlgorithmMember,
30
+ requestAlgorithmMember: requestAlgorithmMember?.name,
27
31
  }, !!context.isS3ExpressBucket);
28
32
  let updatedBody = requestBody;
29
33
  let updatedHeaders = headers;
@@ -0,0 +1,9 @@
1
+ export const hasHeaderWithPrefix = (headerPrefix, headers) => {
2
+ const soughtHeaderPrefix = headerPrefix.toLowerCase();
3
+ for (const headerName of Object.keys(headers)) {
4
+ if (headerName.toLowerCase().startsWith(soughtHeaderPrefix)) {
5
+ return true;
6
+ }
7
+ }
8
+ return false;
9
+ };
@@ -1,10 +1,19 @@
1
1
  import { AwsCrc32c } from "@aws-crypto/crc32c";
2
2
  import { ChecksumAlgorithm } from "./constants";
3
3
  import { getCrc32ChecksumAlgorithmFunction } from "./getCrc32ChecksumAlgorithmFunction";
4
- export const selectChecksumAlgorithmFunction = (checksumAlgorithm, config) => ({
5
- [ChecksumAlgorithm.MD5]: config.md5,
6
- [ChecksumAlgorithm.CRC32]: getCrc32ChecksumAlgorithmFunction(),
7
- [ChecksumAlgorithm.CRC32C]: AwsCrc32c,
8
- [ChecksumAlgorithm.SHA1]: config.sha1,
9
- [ChecksumAlgorithm.SHA256]: config.sha256,
10
- }[checksumAlgorithm]);
4
+ export const selectChecksumAlgorithmFunction = (checksumAlgorithm, config) => {
5
+ switch (checksumAlgorithm) {
6
+ case ChecksumAlgorithm.MD5:
7
+ return config.md5;
8
+ case ChecksumAlgorithm.CRC32:
9
+ return getCrc32ChecksumAlgorithmFunction();
10
+ case ChecksumAlgorithm.CRC32C:
11
+ return AwsCrc32c;
12
+ case ChecksumAlgorithm.SHA1:
13
+ return config.sha1;
14
+ case ChecksumAlgorithm.SHA256:
15
+ return config.sha256;
16
+ default:
17
+ throw new Error(`Unsupported checksum algorithm: ${checksumAlgorithm}`);
18
+ }
19
+ };
@@ -7,14 +7,19 @@ export interface FlexibleChecksumsRequestMiddlewareConfig {
7
7
  */
8
8
  requestChecksumRequired: boolean;
9
9
  /**
10
- * Defines a top-level operation input member that is used to configure request checksum behavior.
10
+ * Member that is used to configure request checksum behavior.
11
11
  */
12
- requestAlgorithmMember?: string;
13
- /**
14
- * The {@link httpHeader} value for {@link requestAlgorithmMember}, if present.
15
- * {@link https://smithy.io/2.0/spec/http-bindings.html#httpheader-trait httpHeader}
16
- */
17
- requestAlgorithmMemberHttpHeader?: string;
12
+ requestAlgorithmMember?: {
13
+ /**
14
+ * Defines a top-level operation input member that is used to configure request checksum behavior.
15
+ */
16
+ name: string;
17
+ /**
18
+ * The {@link httpHeader} value, if present.
19
+ * {@link https://smithy.io/2.0/spec/http-bindings.html#httpheader-trait httpHeader}
20
+ */
21
+ httpHeader?: string;
22
+ };
18
23
  }
19
24
  export declare const flexibleChecksumsMiddlewareOptions: BuildHandlerOptions;
20
25
  /**
@@ -0,0 +1,6 @@
1
+ import { HeaderBag } from "@smithy/types";
2
+ /**
3
+ * Returns true if header with headerPrefix is present in headers.
4
+ * Comparisons are case-insensitive.
5
+ */
6
+ export declare const hasHeaderWithPrefix: (headerPrefix: string, headers: HeaderBag) => boolean;
@@ -2,8 +2,10 @@ import { BuildHandlerOptions, BuildMiddleware } from "@smithy/types";
2
2
  import { PreviouslyResolved } from "./configuration";
3
3
  export interface FlexibleChecksumsRequestMiddlewareConfig {
4
4
  requestChecksumRequired: boolean;
5
- requestAlgorithmMember?: string;
6
- requestAlgorithmMemberHttpHeader?: string;
5
+ requestAlgorithmMember?: {
6
+ name: string;
7
+ httpHeader?: string;
8
+ };
7
9
  }
8
10
  export declare const flexibleChecksumsMiddlewareOptions: BuildHandlerOptions;
9
11
  export declare const flexibleChecksumsMiddleware: (
@@ -0,0 +1,5 @@
1
+ import { HeaderBag } from "@smithy/types";
2
+ export declare const hasHeaderWithPrefix: (
3
+ headerPrefix: string,
4
+ headers: HeaderBag
5
+ ) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/middleware-flexible-checksums",
3
- "version": "3.713.0",
3
+ "version": "3.715.0",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
6
6
  "build:cjs": "node ../../scripts/compilation/inline middleware-flexible-checksums",
@@ -36,8 +36,8 @@
36
36
  "@aws-crypto/crc32": "5.2.0",
37
37
  "@aws-crypto/crc32c": "5.2.0",
38
38
  "@aws-crypto/util": "5.2.0",
39
- "@aws-sdk/core": "3.713.0",
40
- "@aws-sdk/types": "3.713.0",
39
+ "@aws-sdk/core": "3.714.0",
40
+ "@aws-sdk/types": "3.714.0",
41
41
  "@smithy/is-array-buffer": "^3.0.0",
42
42
  "@smithy/node-config-provider": "^3.1.12",
43
43
  "@smithy/protocol-http": "^4.1.8",