@smithy/fetch-http-handler 3.2.9 → 4.1.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.
@@ -0,0 +1 @@
1
+ module.exports = require("./index.js");
package/dist-cjs/index.js CHANGED
@@ -30,6 +30,12 @@ module.exports = __toCommonJS(src_exports);
30
30
  var import_protocol_http = require("@smithy/protocol-http");
31
31
  var import_querystring_builder = require("@smithy/querystring-builder");
32
32
 
33
+ // src/create-request.ts
34
+ function createRequest(url, requestOptions) {
35
+ return new Request(url, requestOptions);
36
+ }
37
+ __name(createRequest, "createRequest");
38
+
33
39
  // src/request-timeout.ts
34
40
  function requestTimeout(timeoutInMs = 0) {
35
41
  return new Promise((resolve, reject) => {
@@ -68,7 +74,7 @@ var _FetchHttpHandler = class _FetchHttpHandler {
68
74
  }
69
75
  if (keepAliveSupport.supported === void 0) {
70
76
  keepAliveSupport.supported = Boolean(
71
- typeof Request !== "undefined" && "keepalive" in new Request("https://[::1]")
77
+ typeof Request !== "undefined" && "keepalive" in createRequest("https://[::1]")
72
78
  );
73
79
  }
74
80
  }
@@ -127,7 +133,7 @@ var _FetchHttpHandler = class _FetchHttpHandler {
127
133
  }
128
134
  let removeSignalEventListener = /* @__PURE__ */ __name(() => {
129
135
  }, "removeSignalEventListener");
130
- const fetchRequest = new Request(url, requestOptions);
136
+ const fetchRequest = createRequest(url, requestOptions);
131
137
  const raceOfPromises = [
132
138
  fetch(fetchRequest).then((response) => {
133
139
  const fetchHeaders = response.headers;
@@ -192,19 +198,13 @@ __name(_FetchHttpHandler, "FetchHttpHandler");
192
198
  var FetchHttpHandler = _FetchHttpHandler;
193
199
 
194
200
  // src/stream-collector.ts
195
- var import_util_base64 = require("@smithy/util-base64");
196
- var streamCollector = /* @__PURE__ */ __name((stream) => {
197
- if (typeof Blob === "function" && stream instanceof Blob) {
198
- return collectBlob(stream);
201
+ var streamCollector = /* @__PURE__ */ __name(async (stream) => {
202
+ var _a;
203
+ if (typeof Blob === "function" && stream instanceof Blob || ((_a = stream.constructor) == null ? void 0 : _a.name) === "Blob") {
204
+ return new Uint8Array(await stream.arrayBuffer());
199
205
  }
200
206
  return collectStream(stream);
201
207
  }, "streamCollector");
202
- async function collectBlob(blob) {
203
- const base64 = await readToBase64(blob);
204
- const arrayBuffer = (0, import_util_base64.fromBase64)(base64);
205
- return new Uint8Array(arrayBuffer);
206
- }
207
- __name(collectBlob, "collectBlob");
208
208
  async function collectStream(stream) {
209
209
  const chunks = [];
210
210
  const reader = stream.getReader();
@@ -227,24 +227,6 @@ async function collectStream(stream) {
227
227
  return collected;
228
228
  }
229
229
  __name(collectStream, "collectStream");
230
- function readToBase64(blob) {
231
- return new Promise((resolve, reject) => {
232
- const reader = new FileReader();
233
- reader.onloadend = () => {
234
- if (reader.readyState !== 2) {
235
- return reject(new Error("Reader aborted too early"));
236
- }
237
- const result = reader.result ?? "";
238
- const commaIndex = result.indexOf(",");
239
- const dataOffset = commaIndex > -1 ? commaIndex + 1 : result.length;
240
- resolve(result.substring(dataOffset));
241
- };
242
- reader.onabort = () => reject(new Error("Read aborted"));
243
- reader.onerror = () => reject(reader.error);
244
- reader.readAsDataURL(blob);
245
- });
246
- }
247
- __name(readToBase64, "readToBase64");
248
230
  // Annotate the CommonJS export names for ESM import in node:
249
231
 
250
232
  0 && (module.exports = {
@@ -0,0 +1,3 @@
1
+ export function createRequest(url, requestOptions) {
2
+ return new Request(url, requestOptions);
3
+ }
@@ -1,5 +1,6 @@
1
1
  import { HttpResponse } from "@smithy/protocol-http";
2
2
  import { buildQueryString } from "@smithy/querystring-builder";
3
+ import { createRequest } from "./create-request";
3
4
  import { requestTimeout } from "./request-timeout";
4
5
  export const keepAliveSupport = {
5
6
  supported: undefined,
@@ -20,7 +21,7 @@ export class FetchHttpHandler {
20
21
  this.configProvider = Promise.resolve(this.config);
21
22
  }
22
23
  if (keepAliveSupport.supported === undefined) {
23
- keepAliveSupport.supported = Boolean(typeof Request !== "undefined" && "keepalive" in new Request("https://[::1]"));
24
+ keepAliveSupport.supported = Boolean(typeof Request !== "undefined" && "keepalive" in createRequest("https://[::1]"));
24
25
  }
25
26
  }
26
27
  destroy() {
@@ -76,7 +77,7 @@ export class FetchHttpHandler {
76
77
  Object.assign(requestOptions, this.config.requestInit(request));
77
78
  }
78
79
  let removeSignalEventListener = () => { };
79
- const fetchRequest = new Request(url, requestOptions);
80
+ const fetchRequest = createRequest(url, requestOptions);
80
81
  const raceOfPromises = [
81
82
  fetch(fetchRequest).then((response) => {
82
83
  const fetchHeaders = response.headers;
@@ -1,15 +1,9 @@
1
- import { fromBase64 } from "@smithy/util-base64";
2
- export const streamCollector = (stream) => {
3
- if (typeof Blob === "function" && stream instanceof Blob) {
4
- return collectBlob(stream);
1
+ export const streamCollector = async (stream) => {
2
+ if ((typeof Blob === "function" && stream instanceof Blob) || stream.constructor?.name === "Blob") {
3
+ return new Uint8Array(await stream.arrayBuffer());
5
4
  }
6
5
  return collectStream(stream);
7
6
  };
8
- async function collectBlob(blob) {
9
- const base64 = await readToBase64(blob);
10
- const arrayBuffer = fromBase64(base64);
11
- return new Uint8Array(arrayBuffer);
12
- }
13
7
  async function collectStream(stream) {
14
8
  const chunks = [];
15
9
  const reader = stream.getReader();
@@ -31,20 +25,3 @@ async function collectStream(stream) {
31
25
  }
32
26
  return collected;
33
27
  }
34
- function readToBase64(blob) {
35
- return new Promise((resolve, reject) => {
36
- const reader = new FileReader();
37
- reader.onloadend = () => {
38
- if (reader.readyState !== 2) {
39
- return reject(new Error("Reader aborted too early"));
40
- }
41
- const result = (reader.result ?? "");
42
- const commaIndex = result.indexOf(",");
43
- const dataOffset = commaIndex > -1 ? commaIndex + 1 : result.length;
44
- resolve(result.substring(dataOffset));
45
- };
46
- reader.onabort = () => reject(new Error("Read aborted"));
47
- reader.onerror = () => reject(reader.error);
48
- reader.readAsDataURL(blob);
49
- });
50
- }
@@ -0,0 +1,6 @@
1
+ import { AdditionalRequestParameters } from "./fetch-http-handler";
2
+ /**
3
+ * @internal
4
+ * For mocking/interception.
5
+ */
6
+ export declare function createRequest(url: string, requestOptions?: RequestInit & AdditionalRequestParameters): Request;
@@ -10,6 +10,12 @@ type FetchHttpHandlerConfig = FetchHttpHandlerOptions;
10
10
  export declare const keepAliveSupport: {
11
11
  supported: boolean | undefined;
12
12
  };
13
+ /**
14
+ * @internal
15
+ */
16
+ export type AdditionalRequestParameters = {
17
+ duplex?: "half";
18
+ };
13
19
  /**
14
20
  * @public
15
21
  *
@@ -0,0 +1,6 @@
1
+ import { AdditionalRequestParameters } from "./fetch-http-handler";
2
+ /**
3
+ * @internal
4
+ * For mocking/interception.
5
+ */
6
+ export declare function createRequest(url: string, requestOptions?: RequestInit & AdditionalRequestParameters): Request;
@@ -10,6 +10,12 @@ type FetchHttpHandlerConfig = FetchHttpHandlerOptions;
10
10
  export declare const keepAliveSupport: {
11
11
  supported: boolean | undefined;
12
12
  };
13
+ /**
14
+ * @internal
15
+ */
16
+ export type AdditionalRequestParameters = {
17
+ duplex?: "half";
18
+ };
13
19
  /**
14
20
  * @public
15
21
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/fetch-http-handler",
3
- "version": "3.2.9",
3
+ "version": "4.1.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'",
@@ -13,7 +13,10 @@
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": "yarn g:jest --coverage --forceExit && yarn g:karma start karma.conf.js"
16
+ "test": "yarn g:vitest run && yarn test:browser",
17
+ "test:watch": "yarn g:vitest watch",
18
+ "test:browser": "yarn g:vitest run -c vitest.config.browser.ts",
19
+ "test:browser:watch": "yarn g:vitest watch -c vitest.config.browser.ts"
17
20
  },
18
21
  "author": {
19
22
  "name": "AWS SDK for JavaScript Team",
@@ -24,14 +27,14 @@
24
27
  "module": "./dist-es/index.js",
25
28
  "types": "./dist-types/index.d.ts",
26
29
  "dependencies": {
27
- "@smithy/protocol-http": "^4.1.4",
28
- "@smithy/querystring-builder": "^3.0.7",
29
- "@smithy/types": "^3.5.0",
30
+ "@smithy/protocol-http": "^4.1.6",
31
+ "@smithy/querystring-builder": "^3.0.9",
32
+ "@smithy/types": "^3.7.0",
30
33
  "@smithy/util-base64": "^3.0.0",
31
34
  "tslib": "^2.6.2"
32
35
  },
33
36
  "devDependencies": {
34
- "@smithy/abort-controller": "^3.1.5",
37
+ "@smithy/abort-controller": "^3.1.7",
35
38
  "concurrently": "7.0.0",
36
39
  "downlevel-dts": "0.10.1",
37
40
  "rimraf": "3.0.2",