@aws-sdk/middleware-expect-continue 3.914.0 → 3.917.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
@@ -5,12 +5,24 @@ var protocolHttp = require('@smithy/protocol-http');
5
5
  function addExpectContinueMiddleware(options) {
6
6
  return (next) => async (args) => {
7
7
  const { request } = args;
8
- if (protocolHttp.HttpRequest.isInstance(request) && request.body && options.runtime === "node") {
9
- if (options.requestHandler?.constructor?.name !== "FetchHttpHandler") {
10
- request.headers = {
11
- ...request.headers,
12
- Expect: "100-continue",
13
- };
8
+ if (options.expectContinueHeader !== false &&
9
+ protocolHttp.HttpRequest.isInstance(request) &&
10
+ request.body &&
11
+ options.runtime === "node" &&
12
+ options.requestHandler?.constructor?.name !== "FetchHttpHandler") {
13
+ let sendHeader = true;
14
+ if (typeof options.expectContinueHeader === "number") {
15
+ try {
16
+ const bodyLength = Number(request.headers?.["content-length"]) ?? options.bodyLengthChecker?.(request.body) ?? Infinity;
17
+ sendHeader = bodyLength >= options.expectContinueHeader;
18
+ }
19
+ catch (e) { }
20
+ }
21
+ else {
22
+ sendHeader = !!options.expectContinueHeader;
23
+ }
24
+ if (sendHeader) {
25
+ request.headers.Expect = "100-continue";
14
26
  }
15
27
  }
16
28
  return next({
package/dist-es/index.js CHANGED
@@ -2,12 +2,24 @@ import { HttpRequest } from "@smithy/protocol-http";
2
2
  export function addExpectContinueMiddleware(options) {
3
3
  return (next) => async (args) => {
4
4
  const { request } = args;
5
- if (HttpRequest.isInstance(request) && request.body && options.runtime === "node") {
6
- if (options.requestHandler?.constructor?.name !== "FetchHttpHandler") {
7
- request.headers = {
8
- ...request.headers,
9
- Expect: "100-continue",
10
- };
5
+ if (options.expectContinueHeader !== false &&
6
+ HttpRequest.isInstance(request) &&
7
+ request.body &&
8
+ options.runtime === "node" &&
9
+ options.requestHandler?.constructor?.name !== "FetchHttpHandler") {
10
+ let sendHeader = true;
11
+ if (typeof options.expectContinueHeader === "number") {
12
+ try {
13
+ const bodyLength = Number(request.headers?.["content-length"]) ?? options.bodyLengthChecker?.(request.body) ?? Infinity;
14
+ sendHeader = bodyLength >= options.expectContinueHeader;
15
+ }
16
+ catch (e) { }
17
+ }
18
+ else {
19
+ sendHeader = !!options.expectContinueHeader;
20
+ }
21
+ if (sendHeader) {
22
+ request.headers.Expect = "100-continue";
11
23
  }
12
24
  }
13
25
  return next({
@@ -1,8 +1,10 @@
1
1
  import { HttpHandler } from "@smithy/protocol-http";
2
- import { BuildHandlerOptions, BuildMiddleware, Pluggable, RequestHandler } from "@smithy/types";
2
+ import type { BodyLengthCalculator, BuildHandlerOptions, BuildMiddleware, Pluggable, RequestHandler } from "@smithy/types";
3
3
  interface PreviouslyResolved {
4
4
  runtime: string;
5
5
  requestHandler?: RequestHandler<any, any, any> | HttpHandler<any>;
6
+ bodyLengthChecker?: BodyLengthCalculator;
7
+ expectContinueHeader?: boolean | number;
6
8
  }
7
9
  export declare function addExpectContinueMiddleware(options: PreviouslyResolved): BuildMiddleware<any, any>;
8
10
  export declare const addExpectContinueMiddlewareOptions: BuildHandlerOptions;
@@ -1,5 +1,6 @@
1
1
  import { HttpHandler } from "@smithy/protocol-http";
2
2
  import {
3
+ BodyLengthCalculator,
3
4
  BuildHandlerOptions,
4
5
  BuildMiddleware,
5
6
  Pluggable,
@@ -8,6 +9,8 @@ import {
8
9
  interface PreviouslyResolved {
9
10
  runtime: string;
10
11
  requestHandler?: RequestHandler<any, any, any> | HttpHandler<any>;
12
+ bodyLengthChecker?: BodyLengthCalculator;
13
+ expectContinueHeader?: boolean | number;
11
14
  }
12
15
  export declare function addExpectContinueMiddleware(
13
16
  options: PreviouslyResolved
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/middleware-expect-continue",
3
- "version": "3.914.0",
3
+ "version": "3.917.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-expect-continue",