@smithy/fetch-http-handler 2.1.5 → 2.2.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.
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FetchHttpHandler = void 0;
3
+ exports.FetchHttpHandler = exports.keepAliveSupport = void 0;
4
4
  const protocol_http_1 = require("@smithy/protocol-http");
5
5
  const querystring_builder_1 = require("@smithy/querystring-builder");
6
6
  const request_timeout_1 = require("./request-timeout");
7
+ exports.keepAliveSupport = {
8
+ supported: Boolean(typeof Request !== "undefined" && "keepalive" in new Request("")),
9
+ };
7
10
  class FetchHttpHandler {
8
11
  constructor(options) {
9
12
  if (typeof options === "function") {
@@ -17,11 +20,12 @@ class FetchHttpHandler {
17
20
  destroy() {
18
21
  }
19
22
  async handle(request, { abortSignal } = {}) {
20
- var _a, _b;
23
+ var _a, _b, _c;
21
24
  if (!this.config) {
22
25
  this.config = await this.configProvider;
23
26
  }
24
27
  const requestTimeoutInMs = this.config.requestTimeout;
28
+ const keepAlive = (_a = this.config.keepAlive) !== null && _a !== void 0 ? _a : true;
25
29
  if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
26
30
  const abortError = new Error("Request aborted");
27
31
  abortError.name = "AbortError";
@@ -37,8 +41,8 @@ class FetchHttpHandler {
37
41
  }
38
42
  let auth = "";
39
43
  if (request.username != null || request.password != null) {
40
- const username = (_a = request.username) !== null && _a !== void 0 ? _a : "";
41
- const password = (_b = request.password) !== null && _b !== void 0 ? _b : "";
44
+ const username = (_b = request.username) !== null && _b !== void 0 ? _b : "";
45
+ const password = (_c = request.password) !== null && _c !== void 0 ? _c : "";
42
46
  auth = `${username}:${password}@`;
43
47
  }
44
48
  const { port, method } = request;
@@ -52,6 +56,9 @@ class FetchHttpHandler {
52
56
  if (typeof AbortController !== "undefined") {
53
57
  requestOptions["signal"] = abortSignal;
54
58
  }
59
+ if (exports.keepAliveSupport.supported) {
60
+ requestOptions["keepalive"] = keepAlive;
61
+ }
55
62
  const fetchRequest = new Request(url, requestOptions);
56
63
  const raceOfPromises = [
57
64
  fetch(fetchRequest).then((response) => {
@@ -1,6 +1,9 @@
1
1
  import { HttpResponse } from "@smithy/protocol-http";
2
2
  import { buildQueryString } from "@smithy/querystring-builder";
3
3
  import { requestTimeout } from "./request-timeout";
4
+ export const keepAliveSupport = {
5
+ supported: Boolean(typeof Request !== "undefined" && "keepalive" in new Request("")),
6
+ };
4
7
  export class FetchHttpHandler {
5
8
  constructor(options) {
6
9
  if (typeof options === "function") {
@@ -18,6 +21,7 @@ export class FetchHttpHandler {
18
21
  this.config = await this.configProvider;
19
22
  }
20
23
  const requestTimeoutInMs = this.config.requestTimeout;
24
+ const keepAlive = this.config.keepAlive ?? true;
21
25
  if (abortSignal?.aborted) {
22
26
  const abortError = new Error("Request aborted");
23
27
  abortError.name = "AbortError";
@@ -48,6 +52,9 @@ export class FetchHttpHandler {
48
52
  if (typeof AbortController !== "undefined") {
49
53
  requestOptions["signal"] = abortSignal;
50
54
  }
55
+ if (keepAliveSupport.supported) {
56
+ requestOptions["keepalive"] = keepAlive;
57
+ }
51
58
  const fetchRequest = new Request(url, requestOptions);
52
59
  const raceOfPromises = [
53
60
  fetch(fetchRequest).then((response) => {
@@ -9,8 +9,24 @@ export interface FetchHttpHandlerOptions {
9
9
  * terminated.
10
10
  */
11
11
  requestTimeout?: number;
12
+ /**
13
+ * Whether to allow the request to outlive the page. Default value is true
14
+ */
15
+ keepAlive?: boolean;
12
16
  }
13
17
  type FetchHttpHandlerConfig = FetchHttpHandlerOptions;
18
+ /**
19
+ * @internal
20
+ * Detection of keepalive support. Can be overridden for testing.
21
+ */
22
+ export declare const keepAliveSupport: {
23
+ supported: boolean;
24
+ };
25
+ /**
26
+ * @public
27
+ *
28
+ * HttpHandler implementation using browsers' `fetch` global function.
29
+ */
14
30
  export declare class FetchHttpHandler implements HttpHandler<FetchHttpHandlerConfig> {
15
31
  private config?;
16
32
  private configProvider;
@@ -9,8 +9,24 @@ export interface FetchHttpHandlerOptions {
9
9
  * terminated.
10
10
  */
11
11
  requestTimeout?: number;
12
+ /**
13
+ * Whether to allow the request to outlive the page. Default value is true
14
+ */
15
+ keepAlive?: boolean;
12
16
  }
13
17
  type FetchHttpHandlerConfig = FetchHttpHandlerOptions;
18
+ /**
19
+ * @internal
20
+ * Detection of keepalive support. Can be overridden for testing.
21
+ */
22
+ export declare const keepAliveSupport: {
23
+ supported: boolean;
24
+ };
25
+ /**
26
+ * @public
27
+ *
28
+ * HttpHandler implementation using browsers' `fetch` global function.
29
+ */
14
30
  export declare class FetchHttpHandler implements HttpHandler<FetchHttpHandlerConfig> {
15
31
  private config?;
16
32
  private configProvider;
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@smithy/fetch-http-handler",
3
- "version": "2.1.5",
3
+ "version": "2.2.0",
4
4
  "description": "Provides a way to make requests",
5
5
  "scripts": {
6
6
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
7
- "build:cjs": "tsc -p tsconfig.cjs.json",
8
- "build:es": "tsc -p tsconfig.es.json",
9
- "build:types": "tsc -p tsconfig.types.json",
7
+ "build:cjs": "yarn g:tsc -p tsconfig.cjs.json",
8
+ "build:es": "yarn g:tsc -p tsconfig.es.json",
9
+ "build:types": "yarn g:tsc -p tsconfig.types.json",
10
10
  "build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
11
11
  "stage-release": "rimraf ./.release && yarn pack && mkdir ./.release && tar zxvf ./package.tgz --directory ./.release && rm ./package.tgz",
12
12
  "clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
13
13
  "lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
14
14
  "format": "prettier --config ../../prettier.config.js --ignore-path ../.prettierignore --write \"**/*.{ts,md,json}\"",
15
15
  "extract:docs": "api-extractor run --local",
16
- "test": "jest --coverage --forceExit && karma start karma.conf.js"
16
+ "test": "yarn g:jest --coverage --forceExit && karma start karma.conf.js"
17
17
  },
18
18
  "author": {
19
19
  "name": "AWS SDK for JavaScript Team",
@@ -24,21 +24,20 @@
24
24
  "module": "./dist-es/index.js",
25
25
  "types": "./dist-types/index.d.ts",
26
26
  "dependencies": {
27
- "@smithy/protocol-http": "^3.0.5",
28
- "@smithy/querystring-builder": "^2.0.9",
29
- "@smithy/types": "^2.3.3",
27
+ "@smithy/protocol-http": "^3.0.6",
28
+ "@smithy/querystring-builder": "^2.0.10",
29
+ "@smithy/types": "^2.3.4",
30
30
  "@smithy/util-base64": "^2.0.0",
31
31
  "tslib": "^2.5.0"
32
32
  },
33
33
  "devDependencies": {
34
- "@smithy/abort-controller": "^2.0.9",
34
+ "@smithy/abort-controller": "^2.0.10",
35
35
  "@tsconfig/recommended": "1.0.1",
36
36
  "@types/chai-as-promised": "^7.1.2",
37
37
  "chai": "^4.2.0",
38
38
  "chai-as-promised": "^7.1.1",
39
39
  "concurrently": "7.0.0",
40
40
  "downlevel-dts": "0.10.1",
41
- "jest": "28.1.1",
42
41
  "karma": "6.4.0",
43
42
  "karma-chai": "0.1.0",
44
43
  "karma-chrome-launcher": "3.1.1",
@@ -52,7 +51,6 @@
52
51
  "karma-webpack": "5.0.0",
53
52
  "rimraf": "3.0.2",
54
53
  "typedoc": "0.23.23",
55
- "typescript": "~4.9.5",
56
54
  "webpack": "5.76.0",
57
55
  "webpack-cli": "4.10.0"
58
56
  },