@smithy/fetch-http-handler 4.1.2 → 4.1.3
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
|
@@ -198,13 +198,23 @@ __name(_FetchHttpHandler, "FetchHttpHandler");
|
|
|
198
198
|
var FetchHttpHandler = _FetchHttpHandler;
|
|
199
199
|
|
|
200
200
|
// src/stream-collector.ts
|
|
201
|
+
var import_util_base64 = require("@smithy/util-base64");
|
|
201
202
|
var streamCollector = /* @__PURE__ */ __name(async (stream) => {
|
|
202
203
|
var _a;
|
|
203
204
|
if (typeof Blob === "function" && stream instanceof Blob || ((_a = stream.constructor) == null ? void 0 : _a.name) === "Blob") {
|
|
204
|
-
|
|
205
|
+
if (Blob.prototype.arrayBuffer !== void 0) {
|
|
206
|
+
return new Uint8Array(await stream.arrayBuffer());
|
|
207
|
+
}
|
|
208
|
+
return collectBlob(stream);
|
|
205
209
|
}
|
|
206
210
|
return collectStream(stream);
|
|
207
211
|
}, "streamCollector");
|
|
212
|
+
async function collectBlob(blob) {
|
|
213
|
+
const base64 = await readToBase64(blob);
|
|
214
|
+
const arrayBuffer = (0, import_util_base64.fromBase64)(base64);
|
|
215
|
+
return new Uint8Array(arrayBuffer);
|
|
216
|
+
}
|
|
217
|
+
__name(collectBlob, "collectBlob");
|
|
208
218
|
async function collectStream(stream) {
|
|
209
219
|
const chunks = [];
|
|
210
220
|
const reader = stream.getReader();
|
|
@@ -227,6 +237,24 @@ async function collectStream(stream) {
|
|
|
227
237
|
return collected;
|
|
228
238
|
}
|
|
229
239
|
__name(collectStream, "collectStream");
|
|
240
|
+
function readToBase64(blob) {
|
|
241
|
+
return new Promise((resolve, reject) => {
|
|
242
|
+
const reader = new FileReader();
|
|
243
|
+
reader.onloadend = () => {
|
|
244
|
+
if (reader.readyState !== 2) {
|
|
245
|
+
return reject(new Error("Reader aborted too early"));
|
|
246
|
+
}
|
|
247
|
+
const result = reader.result ?? "";
|
|
248
|
+
const commaIndex = result.indexOf(",");
|
|
249
|
+
const dataOffset = commaIndex > -1 ? commaIndex + 1 : result.length;
|
|
250
|
+
resolve(result.substring(dataOffset));
|
|
251
|
+
};
|
|
252
|
+
reader.onabort = () => reject(new Error("Read aborted"));
|
|
253
|
+
reader.onerror = () => reject(reader.error);
|
|
254
|
+
reader.readAsDataURL(blob);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
__name(readToBase64, "readToBase64");
|
|
230
258
|
// Annotate the CommonJS export names for ESM import in node:
|
|
231
259
|
|
|
232
260
|
0 && (module.exports = {
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
import { fromBase64 } from "@smithy/util-base64";
|
|
1
2
|
export const streamCollector = async (stream) => {
|
|
2
3
|
if ((typeof Blob === "function" && stream instanceof Blob) || stream.constructor?.name === "Blob") {
|
|
3
|
-
|
|
4
|
+
if (Blob.prototype.arrayBuffer !== undefined) {
|
|
5
|
+
return new Uint8Array(await stream.arrayBuffer());
|
|
6
|
+
}
|
|
7
|
+
return collectBlob(stream);
|
|
4
8
|
}
|
|
5
9
|
return collectStream(stream);
|
|
6
10
|
};
|
|
11
|
+
async function collectBlob(blob) {
|
|
12
|
+
const base64 = await readToBase64(blob);
|
|
13
|
+
const arrayBuffer = fromBase64(base64);
|
|
14
|
+
return new Uint8Array(arrayBuffer);
|
|
15
|
+
}
|
|
7
16
|
async function collectStream(stream) {
|
|
8
17
|
const chunks = [];
|
|
9
18
|
const reader = stream.getReader();
|
|
@@ -25,3 +34,20 @@ async function collectStream(stream) {
|
|
|
25
34
|
}
|
|
26
35
|
return collected;
|
|
27
36
|
}
|
|
37
|
+
function readToBase64(blob) {
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
const reader = new FileReader();
|
|
40
|
+
reader.onloadend = () => {
|
|
41
|
+
if (reader.readyState !== 2) {
|
|
42
|
+
return reject(new Error("Reader aborted too early"));
|
|
43
|
+
}
|
|
44
|
+
const result = (reader.result ?? "");
|
|
45
|
+
const commaIndex = result.indexOf(",");
|
|
46
|
+
const dataOffset = commaIndex > -1 ? commaIndex + 1 : result.length;
|
|
47
|
+
resolve(result.substring(dataOffset));
|
|
48
|
+
};
|
|
49
|
+
reader.onabort = () => reject(new Error("Read aborted"));
|
|
50
|
+
reader.onerror = () => reject(reader.error);
|
|
51
|
+
reader.readAsDataURL(blob);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { HttpHandler, HttpRequest, HttpResponse } from "@smithy/protocol-http";
|
|
2
2
|
import type { FetchHttpHandlerOptions } from "@smithy/types";
|
|
3
3
|
import { HttpHandlerOptions, Provider } from "@smithy/types";
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
4
7
|
export { FetchHttpHandlerOptions };
|
|
5
|
-
type FetchHttpHandlerConfig = FetchHttpHandlerOptions;
|
|
6
8
|
/**
|
|
7
9
|
* @internal
|
|
8
10
|
* Detection of keepalive support. Can be overridden for testing.
|
|
@@ -21,7 +23,7 @@ export type AdditionalRequestParameters = {
|
|
|
21
23
|
*
|
|
22
24
|
* HttpHandler implementation using browsers' `fetch` global function.
|
|
23
25
|
*/
|
|
24
|
-
export declare class FetchHttpHandler implements HttpHandler<
|
|
26
|
+
export declare class FetchHttpHandler implements HttpHandler<FetchHttpHandlerOptions> {
|
|
25
27
|
private config?;
|
|
26
28
|
private configProvider;
|
|
27
29
|
/**
|
|
@@ -34,6 +36,6 @@ export declare class FetchHttpHandler implements HttpHandler<FetchHttpHandlerCon
|
|
|
34
36
|
handle(request: HttpRequest, { abortSignal }?: HttpHandlerOptions): Promise<{
|
|
35
37
|
response: HttpResponse;
|
|
36
38
|
}>;
|
|
37
|
-
updateHttpClientConfig(key: keyof
|
|
38
|
-
httpHandlerConfigs():
|
|
39
|
+
updateHttpClientConfig(key: keyof FetchHttpHandlerOptions, value: FetchHttpHandlerOptions[typeof key]): void;
|
|
40
|
+
httpHandlerConfigs(): FetchHttpHandlerOptions;
|
|
39
41
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { HttpHandler, HttpRequest, HttpResponse } from "@smithy/protocol-http";
|
|
2
2
|
import { FetchHttpHandlerOptions } from "@smithy/types";
|
|
3
3
|
import { HttpHandlerOptions, Provider } from "@smithy/types";
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
4
7
|
export { FetchHttpHandlerOptions };
|
|
5
|
-
type FetchHttpHandlerConfig = FetchHttpHandlerOptions;
|
|
6
8
|
/**
|
|
7
9
|
* @internal
|
|
8
10
|
* Detection of keepalive support. Can be overridden for testing.
|
|
@@ -21,7 +23,7 @@ export type AdditionalRequestParameters = {
|
|
|
21
23
|
*
|
|
22
24
|
* HttpHandler implementation using browsers' `fetch` global function.
|
|
23
25
|
*/
|
|
24
|
-
export declare class FetchHttpHandler implements HttpHandler<
|
|
26
|
+
export declare class FetchHttpHandler implements HttpHandler<FetchHttpHandlerOptions> {
|
|
25
27
|
private config?;
|
|
26
28
|
private configProvider;
|
|
27
29
|
/**
|
|
@@ -34,6 +36,6 @@ export declare class FetchHttpHandler implements HttpHandler<FetchHttpHandlerCon
|
|
|
34
36
|
handle(request: HttpRequest, { abortSignal }?: HttpHandlerOptions): Promise<{
|
|
35
37
|
response: HttpResponse;
|
|
36
38
|
}>;
|
|
37
|
-
updateHttpClientConfig(key: keyof
|
|
38
|
-
httpHandlerConfigs():
|
|
39
|
+
updateHttpClientConfig(key: keyof FetchHttpHandlerOptions, value: FetchHttpHandlerOptions[typeof key]): void;
|
|
40
|
+
httpHandlerConfigs(): FetchHttpHandlerOptions;
|
|
39
41
|
}
|
package/package.json
CHANGED