@aws-sdk/xhr-http-handler 3.485.0 → 3.495.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 +268 -4
- package/dist-cjs/request-timeout.js +1 -13
- package/dist-cjs/xhr-http-handler.js +1 -215
- package/package.json +7 -7
package/dist-cjs/index.js
CHANGED
|
@@ -1,4 +1,268 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
XhrHttpHandler: () => XhrHttpHandler
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
|
|
27
|
+
// src/xhr-http-handler.ts
|
|
28
|
+
var import_protocol_http = require("@smithy/protocol-http");
|
|
29
|
+
var import_querystring_builder = require("@smithy/querystring-builder");
|
|
30
|
+
var import_events = require("events");
|
|
31
|
+
|
|
32
|
+
// src/request-timeout.ts
|
|
33
|
+
var requestTimeout = /* @__PURE__ */ __name((timeoutInMs = 0) => new Promise((resolve, reject) => {
|
|
34
|
+
if (timeoutInMs) {
|
|
35
|
+
setTimeout(() => {
|
|
36
|
+
const timeoutError = new Error(`Request did not complete within ${timeoutInMs} ms`);
|
|
37
|
+
timeoutError.name = "TimeoutError";
|
|
38
|
+
reject(timeoutError);
|
|
39
|
+
}, timeoutInMs);
|
|
40
|
+
}
|
|
41
|
+
}), "requestTimeout");
|
|
42
|
+
|
|
43
|
+
// src/xhr-http-handler.ts
|
|
44
|
+
var EVENTS = {
|
|
45
|
+
get PROGRESS() {
|
|
46
|
+
return "xhr.progress";
|
|
47
|
+
},
|
|
48
|
+
get UPLOAD_PROGRESS() {
|
|
49
|
+
return "xhr.upload.progress";
|
|
50
|
+
},
|
|
51
|
+
get XHR_INSTANTIATED() {
|
|
52
|
+
return "after.xhr.new";
|
|
53
|
+
},
|
|
54
|
+
get BEFORE_XHR_SEND() {
|
|
55
|
+
return "before.xhr.send";
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var _XhrHttpHandler = class _XhrHttpHandler extends import_events.EventEmitter {
|
|
59
|
+
constructor(options) {
|
|
60
|
+
super();
|
|
61
|
+
if (typeof options === "function") {
|
|
62
|
+
this.configProvider = options();
|
|
63
|
+
} else {
|
|
64
|
+
this.config = options ?? {};
|
|
65
|
+
this.configProvider = Promise.resolve(this.config);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @returns the input if it is an HttpHandler of any class,
|
|
70
|
+
* or instantiates a new instance of this handler.
|
|
71
|
+
*/
|
|
72
|
+
static create(instanceOrOptions) {
|
|
73
|
+
if (typeof (instanceOrOptions == null ? void 0 : instanceOrOptions.handle) === "function") {
|
|
74
|
+
return instanceOrOptions;
|
|
75
|
+
}
|
|
76
|
+
return new _XhrHttpHandler(instanceOrOptions);
|
|
77
|
+
}
|
|
78
|
+
updateHttpClientConfig(key, value) {
|
|
79
|
+
this.config = void 0;
|
|
80
|
+
this.configProvider = this.configProvider.then((config) => {
|
|
81
|
+
config[key] = value;
|
|
82
|
+
return config;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
httpHandlerConfigs() {
|
|
86
|
+
return this.config ?? {};
|
|
87
|
+
}
|
|
88
|
+
destroy() {
|
|
89
|
+
}
|
|
90
|
+
async handle(request, { abortSignal } = {}) {
|
|
91
|
+
if (!this.config) {
|
|
92
|
+
this.config = await this.configProvider;
|
|
93
|
+
}
|
|
94
|
+
const requestTimeoutInMs = Number(this.config.requestTimeout) | 0;
|
|
95
|
+
if (abortSignal == null ? void 0 : abortSignal.aborted) {
|
|
96
|
+
const abortError = new Error("Request aborted");
|
|
97
|
+
abortError.name = "AbortError";
|
|
98
|
+
throw abortError;
|
|
99
|
+
}
|
|
100
|
+
let path = request.path;
|
|
101
|
+
if (request.query) {
|
|
102
|
+
const queryString = (0, import_querystring_builder.buildQueryString)(request.query);
|
|
103
|
+
if (queryString) {
|
|
104
|
+
path += `?${queryString}`;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const { port, method } = request;
|
|
108
|
+
const url = `${request.protocol}//${request.hostname}${port ? `:${port}` : ""}${path}`;
|
|
109
|
+
const body = method === "GET" || method === "HEAD" ? void 0 : request.body;
|
|
110
|
+
const xhr = new XMLHttpRequest();
|
|
111
|
+
this.emit(EVENTS.XHR_INSTANTIATED, xhr);
|
|
112
|
+
const raceOfPromises = [
|
|
113
|
+
new Promise((resolve, reject) => {
|
|
114
|
+
let streamCursor = 0;
|
|
115
|
+
let stream;
|
|
116
|
+
let writer;
|
|
117
|
+
xhr.upload.addEventListener("progress", (event) => {
|
|
118
|
+
this.emit(_XhrHttpHandler.EVENTS.UPLOAD_PROGRESS, event, request);
|
|
119
|
+
});
|
|
120
|
+
xhr.addEventListener("progress", (event) => {
|
|
121
|
+
this.emit(_XhrHttpHandler.EVENTS.PROGRESS, event, request);
|
|
122
|
+
});
|
|
123
|
+
xhr.addEventListener("error", (err) => {
|
|
124
|
+
const error = new Error(_XhrHttpHandler.ERROR_IDENTIFIER + ": " + err);
|
|
125
|
+
reject(error);
|
|
126
|
+
});
|
|
127
|
+
xhr.addEventListener("timeout", () => {
|
|
128
|
+
reject(new Error("XMLHttpRequest timed out."));
|
|
129
|
+
});
|
|
130
|
+
xhr.addEventListener("readystatechange", () => {
|
|
131
|
+
const isArrayBuffer = xhr.responseType === "arraybuffer" && xhr.response;
|
|
132
|
+
const isText = !isArrayBuffer && typeof xhr.responseText === "string";
|
|
133
|
+
if (isText && !stream) {
|
|
134
|
+
({ stream, writer } = this.initializeTransformStream());
|
|
135
|
+
}
|
|
136
|
+
switch (xhr.readyState) {
|
|
137
|
+
case XMLHttpRequest.LOADING:
|
|
138
|
+
if (isText) {
|
|
139
|
+
writer.write(streamCursor > 0 ? xhr.responseText.slice(streamCursor) : xhr.responseText);
|
|
140
|
+
streamCursor = xhr.responseText.length;
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
case XMLHttpRequest.DONE:
|
|
144
|
+
const body2 = (() => {
|
|
145
|
+
var _a;
|
|
146
|
+
if (isArrayBuffer) {
|
|
147
|
+
return new Blob([xhr.response]);
|
|
148
|
+
}
|
|
149
|
+
if (isText) {
|
|
150
|
+
streamCursor !== xhr.responseText.length && ((_a = writer.write) == null ? void 0 : _a.call(writer, streamCursor > 0 ? xhr.responseText.slice(streamCursor) : xhr.responseText));
|
|
151
|
+
writer.releaseLock();
|
|
152
|
+
stream.writable.close();
|
|
153
|
+
return stream.readable;
|
|
154
|
+
}
|
|
155
|
+
reject(new Error(`Unexpected XHR response type ${xhr.responseType}. Expected string or arraybuffer.`));
|
|
156
|
+
})();
|
|
157
|
+
resolve({
|
|
158
|
+
response: new import_protocol_http.HttpResponse({
|
|
159
|
+
headers: this.responseHeaders(xhr.getAllResponseHeaders()),
|
|
160
|
+
statusCode: xhr.status,
|
|
161
|
+
body: body2
|
|
162
|
+
})
|
|
163
|
+
});
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
xhr.open(method, url);
|
|
168
|
+
for (const [header, value] of Object.entries(request.headers)) {
|
|
169
|
+
if (!isForbiddenRequestHeader(header)) {
|
|
170
|
+
xhr.setRequestHeader(header, value);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
this.emit(EVENTS.BEFORE_XHR_SEND, xhr);
|
|
174
|
+
xhr.send(body);
|
|
175
|
+
}),
|
|
176
|
+
requestTimeout(requestTimeoutInMs)
|
|
177
|
+
];
|
|
178
|
+
if (abortSignal) {
|
|
179
|
+
raceOfPromises.push(
|
|
180
|
+
new Promise((resolve, reject) => {
|
|
181
|
+
abortSignal.onabort = () => {
|
|
182
|
+
xhr.abort();
|
|
183
|
+
const abortError = new Error("Request aborted");
|
|
184
|
+
abortError.name = "AbortError";
|
|
185
|
+
reject(abortError);
|
|
186
|
+
};
|
|
187
|
+
})
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
return Promise.race(raceOfPromises);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Converts XHR response headers to a map.
|
|
194
|
+
* @param xhrHeaders - string to be parsed.
|
|
195
|
+
*/
|
|
196
|
+
responseHeaders(xhrHeaders) {
|
|
197
|
+
if (!xhrHeaders) {
|
|
198
|
+
return {};
|
|
199
|
+
}
|
|
200
|
+
return xhrHeaders.split("\r\n").reduce((headerMap, line) => {
|
|
201
|
+
const parts = line.split(": ");
|
|
202
|
+
const header = parts.shift();
|
|
203
|
+
const value = parts.join(": ");
|
|
204
|
+
headerMap[header] = value;
|
|
205
|
+
return headerMap;
|
|
206
|
+
}, {});
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* @returns a stream and its default writer to be used to map the xhr response text to a readable stream.
|
|
210
|
+
*/
|
|
211
|
+
initializeTransformStream() {
|
|
212
|
+
const textEncoder = new TextEncoder();
|
|
213
|
+
const stream = new TransformStream({
|
|
214
|
+
start() {
|
|
215
|
+
},
|
|
216
|
+
async transform(chunk, controller) {
|
|
217
|
+
controller.enqueue(textEncoder.encode(String(chunk)));
|
|
218
|
+
},
|
|
219
|
+
flush() {
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
const writer = stream.writable.getWriter();
|
|
223
|
+
return {
|
|
224
|
+
stream,
|
|
225
|
+
writer
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
__name(_XhrHttpHandler, "XhrHttpHandler");
|
|
230
|
+
_XhrHttpHandler.EVENTS = EVENTS;
|
|
231
|
+
_XhrHttpHandler.ERROR_IDENTIFIER = "XHR_HTTP_HANDLER_ERROR";
|
|
232
|
+
var XhrHttpHandler = _XhrHttpHandler;
|
|
233
|
+
var isForbiddenRequestHeader = /* @__PURE__ */ __name((header) => {
|
|
234
|
+
header = header.toLowerCase();
|
|
235
|
+
if (header.startsWith("proxy-")) {
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
if (header.startsWith("sec-")) {
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
return forbiddenHeaders.includes(header);
|
|
242
|
+
}, "isForbiddenRequestHeader");
|
|
243
|
+
var forbiddenHeaders = [
|
|
244
|
+
"Accept-Charset",
|
|
245
|
+
"Accept-Encoding",
|
|
246
|
+
"Access-Control-Request-Headers",
|
|
247
|
+
"Access-Control-Request-Method",
|
|
248
|
+
"Connection",
|
|
249
|
+
"Content-Length",
|
|
250
|
+
"Cookie",
|
|
251
|
+
"Date",
|
|
252
|
+
"DNT",
|
|
253
|
+
"Expect",
|
|
254
|
+
"Feature-Policy",
|
|
255
|
+
"Host",
|
|
256
|
+
"Keep-Alive",
|
|
257
|
+
"Origin",
|
|
258
|
+
"Referer",
|
|
259
|
+
"TE",
|
|
260
|
+
"Trailer",
|
|
261
|
+
"Transfer-Encoding",
|
|
262
|
+
"Upgrade",
|
|
263
|
+
"Via"
|
|
264
|
+
].map((_) => _.toLowerCase());
|
|
265
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
266
|
+
0 && (module.exports = {
|
|
267
|
+
XhrHttpHandler
|
|
268
|
+
});
|
|
@@ -1,13 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.requestTimeout = void 0;
|
|
4
|
-
const requestTimeout = (timeoutInMs = 0) => new Promise((resolve, reject) => {
|
|
5
|
-
if (timeoutInMs) {
|
|
6
|
-
setTimeout(() => {
|
|
7
|
-
const timeoutError = new Error(`Request did not complete within ${timeoutInMs} ms`);
|
|
8
|
-
timeoutError.name = "TimeoutError";
|
|
9
|
-
reject(timeoutError);
|
|
10
|
-
}, timeoutInMs);
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
exports.requestTimeout = requestTimeout;
|
|
1
|
+
module.exports = require("./index.js");
|
|
@@ -1,215 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.XhrHttpHandler = void 0;
|
|
4
|
-
const protocol_http_1 = require("@smithy/protocol-http");
|
|
5
|
-
const querystring_builder_1 = require("@smithy/querystring-builder");
|
|
6
|
-
const events_1 = require("events");
|
|
7
|
-
const request_timeout_1 = require("./request-timeout");
|
|
8
|
-
const EVENTS = {
|
|
9
|
-
get PROGRESS() {
|
|
10
|
-
return "xhr.progress";
|
|
11
|
-
},
|
|
12
|
-
get UPLOAD_PROGRESS() {
|
|
13
|
-
return "xhr.upload.progress";
|
|
14
|
-
},
|
|
15
|
-
get XHR_INSTANTIATED() {
|
|
16
|
-
return "after.xhr.new";
|
|
17
|
-
},
|
|
18
|
-
get BEFORE_XHR_SEND() {
|
|
19
|
-
return "before.xhr.send";
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
class XhrHttpHandler extends events_1.EventEmitter {
|
|
23
|
-
static create(instanceOrOptions) {
|
|
24
|
-
if (typeof (instanceOrOptions === null || instanceOrOptions === void 0 ? void 0 : instanceOrOptions.handle) === "function") {
|
|
25
|
-
return instanceOrOptions;
|
|
26
|
-
}
|
|
27
|
-
return new XhrHttpHandler(instanceOrOptions);
|
|
28
|
-
}
|
|
29
|
-
constructor(options) {
|
|
30
|
-
super();
|
|
31
|
-
if (typeof options === "function") {
|
|
32
|
-
this.configProvider = options();
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
this.config = options !== null && options !== void 0 ? options : {};
|
|
36
|
-
this.configProvider = Promise.resolve(this.config);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
updateHttpClientConfig(key, value) {
|
|
40
|
-
this.config = undefined;
|
|
41
|
-
this.configProvider = this.configProvider.then((config) => {
|
|
42
|
-
config[key] = value;
|
|
43
|
-
return config;
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
httpHandlerConfigs() {
|
|
47
|
-
var _a;
|
|
48
|
-
return (_a = this.config) !== null && _a !== void 0 ? _a : {};
|
|
49
|
-
}
|
|
50
|
-
destroy() {
|
|
51
|
-
}
|
|
52
|
-
async handle(request, { abortSignal } = {}) {
|
|
53
|
-
if (!this.config) {
|
|
54
|
-
this.config = await this.configProvider;
|
|
55
|
-
}
|
|
56
|
-
const requestTimeoutInMs = Number(this.config.requestTimeout) | 0;
|
|
57
|
-
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
|
|
58
|
-
const abortError = new Error("Request aborted");
|
|
59
|
-
abortError.name = "AbortError";
|
|
60
|
-
throw abortError;
|
|
61
|
-
}
|
|
62
|
-
let path = request.path;
|
|
63
|
-
if (request.query) {
|
|
64
|
-
const queryString = (0, querystring_builder_1.buildQueryString)(request.query);
|
|
65
|
-
if (queryString) {
|
|
66
|
-
path += `?${queryString}`;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
const { port, method } = request;
|
|
70
|
-
const url = `${request.protocol}//${request.hostname}${port ? `:${port}` : ""}${path}`;
|
|
71
|
-
const body = method === "GET" || method === "HEAD" ? undefined : request.body;
|
|
72
|
-
const xhr = new XMLHttpRequest();
|
|
73
|
-
this.emit(EVENTS.XHR_INSTANTIATED, xhr);
|
|
74
|
-
const raceOfPromises = [
|
|
75
|
-
new Promise((resolve, reject) => {
|
|
76
|
-
let streamCursor = 0;
|
|
77
|
-
let stream;
|
|
78
|
-
let writer;
|
|
79
|
-
xhr.upload.addEventListener("progress", (event) => {
|
|
80
|
-
this.emit(XhrHttpHandler.EVENTS.UPLOAD_PROGRESS, event, request);
|
|
81
|
-
});
|
|
82
|
-
xhr.addEventListener("progress", (event) => {
|
|
83
|
-
this.emit(XhrHttpHandler.EVENTS.PROGRESS, event, request);
|
|
84
|
-
});
|
|
85
|
-
xhr.addEventListener("error", (err) => {
|
|
86
|
-
const error = new Error(XhrHttpHandler.ERROR_IDENTIFIER + ": " + err);
|
|
87
|
-
reject(error);
|
|
88
|
-
});
|
|
89
|
-
xhr.addEventListener("timeout", () => {
|
|
90
|
-
reject(new Error("XMLHttpRequest timed out."));
|
|
91
|
-
});
|
|
92
|
-
xhr.addEventListener("readystatechange", () => {
|
|
93
|
-
const isArrayBuffer = xhr.responseType === "arraybuffer" && xhr.response;
|
|
94
|
-
const isText = !isArrayBuffer && typeof xhr.responseText === "string";
|
|
95
|
-
if (isText && !stream) {
|
|
96
|
-
({ stream, writer } = this.initializeTransformStream());
|
|
97
|
-
}
|
|
98
|
-
switch (xhr.readyState) {
|
|
99
|
-
case XMLHttpRequest.LOADING:
|
|
100
|
-
if (isText) {
|
|
101
|
-
writer.write(streamCursor > 0 ? xhr.responseText.slice(streamCursor) : xhr.responseText);
|
|
102
|
-
streamCursor = xhr.responseText.length;
|
|
103
|
-
}
|
|
104
|
-
break;
|
|
105
|
-
case XMLHttpRequest.DONE:
|
|
106
|
-
const body = (() => {
|
|
107
|
-
var _a;
|
|
108
|
-
if (isArrayBuffer) {
|
|
109
|
-
return new Blob([xhr.response]);
|
|
110
|
-
}
|
|
111
|
-
if (isText) {
|
|
112
|
-
streamCursor !== xhr.responseText.length &&
|
|
113
|
-
((_a = writer.write) === null || _a === void 0 ? void 0 : _a.call(writer, streamCursor > 0 ? xhr.responseText.slice(streamCursor) : xhr.responseText));
|
|
114
|
-
writer.releaseLock();
|
|
115
|
-
stream.writable.close();
|
|
116
|
-
return stream.readable;
|
|
117
|
-
}
|
|
118
|
-
reject(new Error(`Unexpected XHR response type ${xhr.responseType}. Expected string or arraybuffer.`));
|
|
119
|
-
})();
|
|
120
|
-
resolve({
|
|
121
|
-
response: new protocol_http_1.HttpResponse({
|
|
122
|
-
headers: this.responseHeaders(xhr.getAllResponseHeaders()),
|
|
123
|
-
statusCode: xhr.status,
|
|
124
|
-
body,
|
|
125
|
-
}),
|
|
126
|
-
});
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
xhr.open(method, url);
|
|
131
|
-
for (const [header, value] of Object.entries(request.headers)) {
|
|
132
|
-
if (!isForbiddenRequestHeader(header)) {
|
|
133
|
-
xhr.setRequestHeader(header, value);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
this.emit(EVENTS.BEFORE_XHR_SEND, xhr);
|
|
137
|
-
xhr.send(body);
|
|
138
|
-
}),
|
|
139
|
-
(0, request_timeout_1.requestTimeout)(requestTimeoutInMs),
|
|
140
|
-
];
|
|
141
|
-
if (abortSignal) {
|
|
142
|
-
raceOfPromises.push(new Promise((resolve, reject) => {
|
|
143
|
-
abortSignal.onabort = () => {
|
|
144
|
-
xhr.abort();
|
|
145
|
-
const abortError = new Error("Request aborted");
|
|
146
|
-
abortError.name = "AbortError";
|
|
147
|
-
reject(abortError);
|
|
148
|
-
};
|
|
149
|
-
}));
|
|
150
|
-
}
|
|
151
|
-
return Promise.race(raceOfPromises);
|
|
152
|
-
}
|
|
153
|
-
responseHeaders(xhrHeaders) {
|
|
154
|
-
if (!xhrHeaders) {
|
|
155
|
-
return {};
|
|
156
|
-
}
|
|
157
|
-
return xhrHeaders.split("\r\n").reduce((headerMap, line) => {
|
|
158
|
-
const parts = line.split(": ");
|
|
159
|
-
const header = parts.shift();
|
|
160
|
-
const value = parts.join(": ");
|
|
161
|
-
headerMap[header] = value;
|
|
162
|
-
return headerMap;
|
|
163
|
-
}, {});
|
|
164
|
-
}
|
|
165
|
-
initializeTransformStream() {
|
|
166
|
-
const textEncoder = new TextEncoder();
|
|
167
|
-
const stream = new TransformStream({
|
|
168
|
-
start() { },
|
|
169
|
-
async transform(chunk, controller) {
|
|
170
|
-
controller.enqueue(textEncoder.encode(String(chunk)));
|
|
171
|
-
},
|
|
172
|
-
flush() { },
|
|
173
|
-
});
|
|
174
|
-
const writer = stream.writable.getWriter();
|
|
175
|
-
return {
|
|
176
|
-
stream,
|
|
177
|
-
writer,
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
exports.XhrHttpHandler = XhrHttpHandler;
|
|
182
|
-
XhrHttpHandler.EVENTS = EVENTS;
|
|
183
|
-
XhrHttpHandler.ERROR_IDENTIFIER = "XHR_HTTP_HANDLER_ERROR";
|
|
184
|
-
const isForbiddenRequestHeader = (header) => {
|
|
185
|
-
header = header.toLowerCase();
|
|
186
|
-
if (header.startsWith("proxy-")) {
|
|
187
|
-
return true;
|
|
188
|
-
}
|
|
189
|
-
if (header.startsWith("sec-")) {
|
|
190
|
-
return true;
|
|
191
|
-
}
|
|
192
|
-
return forbiddenHeaders.includes(header);
|
|
193
|
-
};
|
|
194
|
-
const forbiddenHeaders = [
|
|
195
|
-
"Accept-Charset",
|
|
196
|
-
"Accept-Encoding",
|
|
197
|
-
"Access-Control-Request-Headers",
|
|
198
|
-
"Access-Control-Request-Method",
|
|
199
|
-
"Connection",
|
|
200
|
-
"Content-Length",
|
|
201
|
-
"Cookie",
|
|
202
|
-
"Date",
|
|
203
|
-
"DNT",
|
|
204
|
-
"Expect",
|
|
205
|
-
"Feature-Policy",
|
|
206
|
-
"Host",
|
|
207
|
-
"Keep-Alive",
|
|
208
|
-
"Origin",
|
|
209
|
-
"Referer",
|
|
210
|
-
"TE",
|
|
211
|
-
"Trailer",
|
|
212
|
-
"Transfer-Encoding",
|
|
213
|
-
"Upgrade",
|
|
214
|
-
"Via",
|
|
215
|
-
].map((_) => _.toLowerCase());
|
|
1
|
+
module.exports = require("./index.js");
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/xhr-http-handler",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.495.0",
|
|
4
4
|
"description": "Provides a way to make requests using XMLHttpRequest",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
7
|
-
"build:cjs": "
|
|
7
|
+
"build:cjs": "node ../../scripts/compilation/inline xhr-http-handler",
|
|
8
8
|
"build:es": "tsc -p tsconfig.es.json",
|
|
9
9
|
"build:include:deps": "lerna run --scope $npm_package_name --include-dependencies build",
|
|
10
10
|
"build:types": "tsc -p tsconfig.types.json",
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
"module": "./dist-es/index.js",
|
|
20
20
|
"types": "./dist-types/index.d.ts",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@aws-sdk/types": "3.
|
|
23
|
-
"@smithy/protocol-http": "^3.0
|
|
24
|
-
"@smithy/querystring-builder": "^2.0
|
|
25
|
-
"@smithy/types": "^2.
|
|
22
|
+
"@aws-sdk/types": "3.495.0",
|
|
23
|
+
"@smithy/protocol-http": "^3.1.0",
|
|
24
|
+
"@smithy/querystring-builder": "^2.1.0",
|
|
25
|
+
"@smithy/types": "^2.9.0",
|
|
26
26
|
"events": "3.3.0",
|
|
27
27
|
"tslib": "^2.5.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@smithy/abort-controller": "^2.0
|
|
30
|
+
"@smithy/abort-controller": "^2.1.0",
|
|
31
31
|
"@tsconfig/recommended": "1.0.1",
|
|
32
32
|
"concurrently": "7.0.0",
|
|
33
33
|
"downlevel-dts": "0.10.1",
|