@smithy/fetch-http-handler 2.5.0 → 3.0.1
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/README.md +7 -0
- package/dist-cjs/index.js +21 -9
- package/dist-es/fetch-http-handler.js +10 -3
- package/dist-es/stream-collector.js +11 -6
- package/package.json +8 -25
package/README.md
CHANGED
|
@@ -2,3 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@smithy/fetch-http-handler)
|
|
4
4
|
[](https://www.npmjs.com/package/@smithy/fetch-http-handler)
|
|
5
|
+
|
|
6
|
+
This is the default `requestHandler` used for browser applications.
|
|
7
|
+
Since Node.js introduced experimental Web Streams API in v16.5.0 and made it stable in v21.0.0,
|
|
8
|
+
you can consider using `fetch-http-handler` in Node.js, although it's not recommended.
|
|
9
|
+
|
|
10
|
+
For the Node.js default `requestHandler` implementation, see instead
|
|
11
|
+
[`@smithy/node-http-handler`](https://www.npmjs.com/package/@smithy/node-http-handler).
|
package/dist-cjs/index.js
CHANGED
|
@@ -97,12 +97,19 @@ var _FetchHttpHandler = class _FetchHttpHandler {
|
|
|
97
97
|
const { port, method } = request;
|
|
98
98
|
const url = `${request.protocol}//${auth}${request.hostname}${port ? `:${port}` : ""}${path}`;
|
|
99
99
|
const body = method === "GET" || method === "HEAD" ? void 0 : request.body;
|
|
100
|
-
const requestOptions = {
|
|
100
|
+
const requestOptions = {
|
|
101
|
+
body,
|
|
102
|
+
headers: new Headers(request.headers),
|
|
103
|
+
method
|
|
104
|
+
};
|
|
105
|
+
if (body) {
|
|
106
|
+
requestOptions.duplex = "half";
|
|
107
|
+
}
|
|
101
108
|
if (typeof AbortController !== "undefined") {
|
|
102
|
-
requestOptions
|
|
109
|
+
requestOptions.signal = abortSignal;
|
|
103
110
|
}
|
|
104
111
|
if (keepAliveSupport.supported) {
|
|
105
|
-
requestOptions
|
|
112
|
+
requestOptions.keepalive = keepAlive;
|
|
106
113
|
}
|
|
107
114
|
const fetchRequest = new Request(url, requestOptions);
|
|
108
115
|
const raceOfPromises = [
|
|
@@ -176,20 +183,25 @@ async function collectBlob(blob) {
|
|
|
176
183
|
}
|
|
177
184
|
__name(collectBlob, "collectBlob");
|
|
178
185
|
async function collectStream(stream) {
|
|
179
|
-
|
|
186
|
+
const chunks = [];
|
|
180
187
|
const reader = stream.getReader();
|
|
181
188
|
let isDone = false;
|
|
189
|
+
let length = 0;
|
|
182
190
|
while (!isDone) {
|
|
183
191
|
const { done, value } = await reader.read();
|
|
184
192
|
if (value) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
res.set(prior);
|
|
188
|
-
res.set(value, prior.length);
|
|
193
|
+
chunks.push(value);
|
|
194
|
+
length += value.length;
|
|
189
195
|
}
|
|
190
196
|
isDone = done;
|
|
191
197
|
}
|
|
192
|
-
|
|
198
|
+
const collected = new Uint8Array(length);
|
|
199
|
+
let offset = 0;
|
|
200
|
+
for (const chunk of chunks) {
|
|
201
|
+
collected.set(chunk, offset);
|
|
202
|
+
offset += chunk.length;
|
|
203
|
+
}
|
|
204
|
+
return collected;
|
|
193
205
|
}
|
|
194
206
|
__name(collectStream, "collectStream");
|
|
195
207
|
function readToBase64(blob) {
|
|
@@ -50,12 +50,19 @@ export class FetchHttpHandler {
|
|
|
50
50
|
const { port, method } = request;
|
|
51
51
|
const url = `${request.protocol}//${auth}${request.hostname}${port ? `:${port}` : ""}${path}`;
|
|
52
52
|
const body = method === "GET" || method === "HEAD" ? undefined : request.body;
|
|
53
|
-
const requestOptions = {
|
|
53
|
+
const requestOptions = {
|
|
54
|
+
body,
|
|
55
|
+
headers: new Headers(request.headers),
|
|
56
|
+
method: method,
|
|
57
|
+
};
|
|
58
|
+
if (body) {
|
|
59
|
+
requestOptions.duplex = "half";
|
|
60
|
+
}
|
|
54
61
|
if (typeof AbortController !== "undefined") {
|
|
55
|
-
requestOptions
|
|
62
|
+
requestOptions.signal = abortSignal;
|
|
56
63
|
}
|
|
57
64
|
if (keepAliveSupport.supported) {
|
|
58
|
-
requestOptions
|
|
65
|
+
requestOptions.keepalive = keepAlive;
|
|
59
66
|
}
|
|
60
67
|
const fetchRequest = new Request(url, requestOptions);
|
|
61
68
|
const raceOfPromises = [
|
|
@@ -11,20 +11,25 @@ async function collectBlob(blob) {
|
|
|
11
11
|
return new Uint8Array(arrayBuffer);
|
|
12
12
|
}
|
|
13
13
|
async function collectStream(stream) {
|
|
14
|
-
|
|
14
|
+
const chunks = [];
|
|
15
15
|
const reader = stream.getReader();
|
|
16
16
|
let isDone = false;
|
|
17
|
+
let length = 0;
|
|
17
18
|
while (!isDone) {
|
|
18
19
|
const { done, value } = await reader.read();
|
|
19
20
|
if (value) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
res.set(prior);
|
|
23
|
-
res.set(value, prior.length);
|
|
21
|
+
chunks.push(value);
|
|
22
|
+
length += value.length;
|
|
24
23
|
}
|
|
25
24
|
isDone = done;
|
|
26
25
|
}
|
|
27
|
-
|
|
26
|
+
const collected = new Uint8Array(length);
|
|
27
|
+
let offset = 0;
|
|
28
|
+
for (const chunk of chunks) {
|
|
29
|
+
collected.set(chunk, offset);
|
|
30
|
+
offset += chunk.length;
|
|
31
|
+
}
|
|
32
|
+
return collected;
|
|
28
33
|
}
|
|
29
34
|
function readToBase64(blob) {
|
|
30
35
|
return new Promise((resolve, reject) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithy/fetch-http-handler",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
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,7 @@
|
|
|
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 && karma start karma.conf.js"
|
|
16
|
+
"test": "yarn g:jest --coverage --forceExit && yarn g:karma start karma.conf.js"
|
|
17
17
|
},
|
|
18
18
|
"author": {
|
|
19
19
|
"name": "AWS SDK for JavaScript Team",
|
|
@@ -24,35 +24,18 @@
|
|
|
24
24
|
"module": "./dist-es/index.js",
|
|
25
25
|
"types": "./dist-types/index.d.ts",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@smithy/protocol-http": "^
|
|
28
|
-
"@smithy/querystring-builder": "^
|
|
29
|
-
"@smithy/types": "^
|
|
30
|
-
"@smithy/util-base64": "^
|
|
27
|
+
"@smithy/protocol-http": "^4.0.0",
|
|
28
|
+
"@smithy/querystring-builder": "^3.0.0",
|
|
29
|
+
"@smithy/types": "^3.0.0",
|
|
30
|
+
"@smithy/util-base64": "^3.0.0",
|
|
31
31
|
"tslib": "^2.6.2"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@smithy/abort-controller": "^
|
|
35
|
-
"@tsconfig/recommended": "1.0.1",
|
|
36
|
-
"@types/chai-as-promised": "^7.1.2",
|
|
37
|
-
"chai": "^4.2.0",
|
|
38
|
-
"chai-as-promised": "^7.1.1",
|
|
34
|
+
"@smithy/abort-controller": "^3.0.0",
|
|
39
35
|
"concurrently": "7.0.0",
|
|
40
36
|
"downlevel-dts": "0.10.1",
|
|
41
|
-
"karma": "6.4.0",
|
|
42
|
-
"karma-chai": "0.1.0",
|
|
43
|
-
"karma-chrome-launcher": "3.1.1",
|
|
44
|
-
"karma-coverage": "2.2.1",
|
|
45
|
-
"karma-env-preprocessor": "0.1.1",
|
|
46
|
-
"karma-firefox-launcher": "2.1.3",
|
|
47
|
-
"karma-jasmine": "5.1.0",
|
|
48
|
-
"karma-mocha": "2.0.1",
|
|
49
|
-
"karma-sourcemap-loader": "0.3.8",
|
|
50
|
-
"karma-typescript": "5.5.3",
|
|
51
|
-
"karma-webpack": "5.0.0",
|
|
52
37
|
"rimraf": "3.0.2",
|
|
53
|
-
"typedoc": "0.23.23"
|
|
54
|
-
"webpack": "5.76.0",
|
|
55
|
-
"webpack-cli": "4.10.0"
|
|
38
|
+
"typedoc": "0.23.23"
|
|
56
39
|
},
|
|
57
40
|
"typesVersions": {
|
|
58
41
|
"<4.0": {
|