@mswjs/interceptors 0.22.9 → 0.22.11
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/lib/browser/{Interceptor-c794917d.d.ts → Interceptor-c8fc448a.d.ts} +3 -3
- package/lib/browser/{chunk-GL6Y4E24.mjs → chunk-4W72RMFC.mjs} +19 -14
- package/lib/browser/{chunk-OK5YCL7L.js → chunk-ECRLBCQN.js} +55 -55
- package/lib/browser/{chunk-2Z7B3HL5.js → chunk-EGQUVEJ3.js} +23 -18
- package/lib/browser/{chunk-2EIH6L6D.js → chunk-KCAWLR7J.js} +25 -25
- package/lib/browser/{chunk-PGR64QLT.mjs → chunk-MJZRQFUP.mjs} +72 -58
- package/lib/browser/{chunk-BVV2ZW34.js → chunk-NHFEA72Q.js} +79 -65
- package/lib/browser/{chunk-2GVXYEMC.mjs → chunk-O7B67YBY.mjs} +54 -54
- package/lib/browser/{chunk-65HGG3CV.mjs → chunk-UYUNRMLU.mjs} +1 -1
- package/lib/browser/index.d.ts +3 -3
- package/lib/browser/index.js +8 -8
- package/lib/browser/index.mjs +6 -6
- package/lib/browser/interceptors/XMLHttpRequest/index.d.ts +2 -2
- package/lib/browser/interceptors/XMLHttpRequest/index.js +4 -4
- package/lib/browser/interceptors/XMLHttpRequest/index.mjs +3 -3
- package/lib/browser/interceptors/fetch/index.d.ts +2 -2
- package/lib/browser/interceptors/fetch/index.js +3 -3
- package/lib/browser/interceptors/fetch/index.mjs +2 -2
- package/lib/browser/presets/browser.d.ts +2 -2
- package/lib/browser/presets/browser.js +6 -6
- package/lib/browser/presets/browser.mjs +4 -4
- package/lib/node/{BatchInterceptor-5c1e5de3.d.ts → BatchInterceptor-fe69020d.d.ts} +1 -1
- package/lib/node/{Interceptor-b3a4098c.d.ts → Interceptor-f9dfe016.d.ts} +3 -3
- package/lib/node/RemoteHttpInterceptor.d.ts +3 -3
- package/lib/node/RemoteHttpInterceptor.js +25 -19
- package/lib/node/RemoteHttpInterceptor.mjs +21 -15
- package/lib/node/{chunk-F7BBA6FT.js → chunk-2OJRZCGS.js} +76 -62
- package/lib/node/{chunk-6CRMKMDL.mjs → chunk-3V5OWTY7.mjs} +54 -55
- package/lib/node/{chunk-62KFIM4W.js → chunk-6KJ5M2VR.js} +56 -57
- package/lib/node/{chunk-62MBJHEQ.js → chunk-7XU7Q63W.js} +116 -98
- package/lib/node/{chunk-MUUQLKVJ.js → chunk-PKB2CXQV.js} +3 -3
- package/lib/node/{chunk-SFLY7F52.js → chunk-RJMXHEGJ.js} +6 -6
- package/lib/node/{chunk-X3TLFWGD.mjs → chunk-RL5IV5PL.mjs} +72 -58
- package/lib/node/{chunk-RFVEKRYP.mjs → chunk-S5A4P4BZ.mjs} +1 -1
- package/lib/node/{chunk-IC6Y7RGW.mjs → chunk-SBAVVQIW.mjs} +5 -5
- package/lib/node/{chunk-O7RUZJPG.mjs → chunk-XVHIXGXD.mjs} +116 -98
- package/lib/node/index.d.ts +3 -3
- package/lib/node/index.js +4 -4
- package/lib/node/index.mjs +3 -3
- package/lib/node/interceptors/ClientRequest/index.d.ts +2 -2
- package/lib/node/interceptors/ClientRequest/index.js +3 -3
- package/lib/node/interceptors/ClientRequest/index.mjs +2 -2
- package/lib/node/interceptors/XMLHttpRequest/index.d.ts +2 -2
- package/lib/node/interceptors/XMLHttpRequest/index.js +4 -4
- package/lib/node/interceptors/XMLHttpRequest/index.mjs +3 -3
- package/lib/node/interceptors/fetch/index.d.ts +2 -2
- package/lib/node/interceptors/fetch/index.js +20 -15
- package/lib/node/interceptors/fetch/index.mjs +19 -14
- package/lib/node/presets/node.d.ts +2 -2
- package/lib/node/presets/node.js +6 -6
- package/lib/node/presets/node.mjs +4 -4
- package/package.json +3 -4
- package/src/BatchInterceptor.ts +4 -4
- package/src/Interceptor.ts +27 -27
- package/src/RemoteHttpInterceptor.ts +16 -10
- package/src/interceptors/ClientRequest/NodeClientRequest.test.ts +11 -11
- package/src/interceptors/ClientRequest/NodeClientRequest.ts +53 -42
- package/src/interceptors/ClientRequest/http.request.ts +3 -3
- package/src/interceptors/ClientRequest/index.ts +4 -4
- package/src/interceptors/ClientRequest/utils/createRequest.test.ts +5 -5
- package/src/interceptors/ClientRequest/utils/getIncomingMessageBody.ts +7 -7
- package/src/interceptors/ClientRequest/utils/normalizeClientRequestArgs.ts +27 -27
- package/src/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.ts +4 -4
- package/src/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.ts +7 -4
- package/src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts +47 -36
- package/src/interceptors/XMLHttpRequest/XMLHttpRequestProxy.ts +21 -17
- package/src/interceptors/XMLHttpRequest/index.ts +5 -5
- package/src/interceptors/fetch/index.ts +19 -14
- package/src/utils/AsyncEventEmitter.ts +27 -27
- package/src/utils/cloneObject.ts +7 -7
- package/src/utils/getUrlByRequestOptions.ts +13 -13
- package/src/utils/debug.ts +0 -4
|
@@ -3,9 +3,8 @@ import {
|
|
|
3
3
|
uuidv4
|
|
4
4
|
} from "./chunk-STA6QBYM.mjs";
|
|
5
5
|
import {
|
|
6
|
-
Interceptor
|
|
7
|
-
|
|
8
|
-
} from "./chunk-6CRMKMDL.mjs";
|
|
6
|
+
Interceptor
|
|
7
|
+
} from "./chunk-3V5OWTY7.mjs";
|
|
9
8
|
|
|
10
9
|
// src/interceptors/ClientRequest/index.ts
|
|
11
10
|
import http from "http";
|
|
@@ -16,9 +15,10 @@ import { ClientRequest, IncomingMessage as IncomingMessage2 } from "http";
|
|
|
16
15
|
import { until } from "@open-draft/until";
|
|
17
16
|
|
|
18
17
|
// src/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.ts
|
|
19
|
-
|
|
18
|
+
import { Logger } from "@open-draft/logger";
|
|
19
|
+
var logger = new Logger("utils getUrlByRequestOptions");
|
|
20
20
|
function normalizeClientRequestEndArgs(...args) {
|
|
21
|
-
|
|
21
|
+
logger.info("arguments", args);
|
|
22
22
|
const normalizedArgs = new Array(3).fill(null).map((value, index) => args[index] || value);
|
|
23
23
|
normalizedArgs.sort((a, b) => {
|
|
24
24
|
if (typeof a === "function") {
|
|
@@ -32,14 +32,15 @@ function normalizeClientRequestEndArgs(...args) {
|
|
|
32
32
|
}
|
|
33
33
|
return 0;
|
|
34
34
|
});
|
|
35
|
-
|
|
35
|
+
logger.info("normalized args", normalizedArgs);
|
|
36
36
|
return normalizedArgs;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// src/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.ts
|
|
40
|
-
|
|
40
|
+
import { Logger as Logger2 } from "@open-draft/logger";
|
|
41
|
+
var logger2 = new Logger2("http normalizeWriteArgs");
|
|
41
42
|
function normalizeClientRequestWriteArgs(args) {
|
|
42
|
-
|
|
43
|
+
logger2.info("normalizing ClientRequest.write arguments...", args);
|
|
43
44
|
const chunk = args[0];
|
|
44
45
|
const encoding = typeof args[1] === "string" ? args[1] : void 0;
|
|
45
46
|
const callback = typeof args[1] === "function" ? args[1] : args[2];
|
|
@@ -48,7 +49,10 @@ function normalizeClientRequestWriteArgs(args) {
|
|
|
48
49
|
encoding,
|
|
49
50
|
callback
|
|
50
51
|
];
|
|
51
|
-
|
|
52
|
+
logger2.info(
|
|
53
|
+
"successfully normalized ClientRequest.write arguments:",
|
|
54
|
+
writeArgs
|
|
55
|
+
);
|
|
52
56
|
return writeArgs;
|
|
53
57
|
}
|
|
54
58
|
|
|
@@ -142,10 +146,10 @@ var _NodeClientRequest = class extends ClientRequest {
|
|
|
142
146
|
super(requestOptions, callback);
|
|
143
147
|
this.chunks = [];
|
|
144
148
|
this.responseSource = "mock";
|
|
145
|
-
this.
|
|
149
|
+
this.logger = options.logger.extend(
|
|
146
150
|
`request ${requestOptions.method} ${url.href}`
|
|
147
151
|
);
|
|
148
|
-
this.
|
|
152
|
+
this.logger.info("constructing ClientRequest using options:", {
|
|
149
153
|
url,
|
|
150
154
|
requestOptions,
|
|
151
155
|
callback
|
|
@@ -168,22 +172,25 @@ var _NodeClientRequest = class extends ClientRequest {
|
|
|
168
172
|
write(...args) {
|
|
169
173
|
var _a;
|
|
170
174
|
const [chunk, encoding, callback] = normalizeClientRequestWriteArgs(args);
|
|
171
|
-
this.
|
|
175
|
+
this.logger.info("write:", { chunk, encoding, callback });
|
|
172
176
|
this.chunks.push({ chunk, encoding });
|
|
173
177
|
this.writeRequestBodyChunk(chunk, encoding);
|
|
174
|
-
this.
|
|
178
|
+
this.logger.info(
|
|
179
|
+
"chunk successfully stored!",
|
|
180
|
+
(_a = this.requestBuffer) == null ? void 0 : _a.byteLength
|
|
181
|
+
);
|
|
175
182
|
if (!chunk || chunk.length === 0) {
|
|
176
|
-
this.
|
|
183
|
+
this.logger.info("written chunk is empty, skipping callback...");
|
|
177
184
|
} else {
|
|
178
185
|
callback == null ? void 0 : callback();
|
|
179
186
|
}
|
|
180
187
|
return true;
|
|
181
188
|
}
|
|
182
189
|
end(...args) {
|
|
183
|
-
this.
|
|
190
|
+
this.logger.info("end", args);
|
|
184
191
|
const requestId = uuidv4();
|
|
185
192
|
const [chunk, encoding, callback] = normalizeClientRequestEndArgs(...args);
|
|
186
|
-
this.
|
|
193
|
+
this.logger.info("normalized arguments:", { chunk, encoding, callback });
|
|
187
194
|
this.writeRequestBodyChunk(chunk, encoding || void 0);
|
|
188
195
|
const capturedRequest = createRequest(this);
|
|
189
196
|
const interactiveRequest = toInteractiveRequest(capturedRequest);
|
|
@@ -191,7 +198,7 @@ var _NodeClientRequest = class extends ClientRequest {
|
|
|
191
198
|
this.removeHeader("X-Request-Id");
|
|
192
199
|
return this.passthrough(chunk, encoding, callback);
|
|
193
200
|
}
|
|
194
|
-
this.
|
|
201
|
+
this.logger.info(
|
|
195
202
|
'emitting the "request" event for %d listener(s)...',
|
|
196
203
|
this.emitter.listenerCount("request")
|
|
197
204
|
);
|
|
@@ -204,41 +211,46 @@ var _NodeClientRequest = class extends ClientRequest {
|
|
|
204
211
|
}
|
|
205
212
|
);
|
|
206
213
|
const [mockedResponse] = await interactiveRequest.respondWith.invoked();
|
|
207
|
-
this.
|
|
214
|
+
this.logger.info("event.respondWith called with:", mockedResponse);
|
|
208
215
|
return mockedResponse;
|
|
209
|
-
}).then((
|
|
210
|
-
this.
|
|
216
|
+
}).then((resolverResult) => {
|
|
217
|
+
this.logger.info("the listeners promise awaited!");
|
|
211
218
|
if (!this.headersSent) {
|
|
212
219
|
for (const [headerName, headerValue] of capturedRequest.headers) {
|
|
213
220
|
this.setHeader(headerName, headerValue);
|
|
214
221
|
}
|
|
215
222
|
}
|
|
216
|
-
if (
|
|
217
|
-
this.
|
|
223
|
+
if (resolverResult.error) {
|
|
224
|
+
this.logger.info(
|
|
218
225
|
"encountered resolver exception, aborting request...",
|
|
219
|
-
|
|
226
|
+
resolverResult.error
|
|
220
227
|
);
|
|
221
|
-
this.emit("error",
|
|
228
|
+
this.emit("error", resolverResult.error);
|
|
222
229
|
this.terminate();
|
|
223
230
|
return this;
|
|
224
231
|
}
|
|
232
|
+
const mockedResponse = resolverResult.data;
|
|
225
233
|
if (mockedResponse) {
|
|
226
234
|
const responseClone = mockedResponse.clone();
|
|
227
|
-
this.
|
|
235
|
+
this.logger.info("received mocked response:", mockedResponse);
|
|
228
236
|
this.responseSource = "mock";
|
|
229
237
|
this.respondWith(mockedResponse);
|
|
230
|
-
this.
|
|
238
|
+
this.logger.info(
|
|
239
|
+
mockedResponse.status,
|
|
240
|
+
mockedResponse.statusText,
|
|
241
|
+
"(MOCKED)"
|
|
242
|
+
);
|
|
231
243
|
callback == null ? void 0 : callback();
|
|
232
|
-
this.
|
|
244
|
+
this.logger.info('emitting the custom "response" event...');
|
|
233
245
|
this.emitter.emit("response", responseClone, capturedRequest, requestId);
|
|
234
|
-
this.
|
|
246
|
+
this.logger.info("request (mock) is completed");
|
|
235
247
|
return this;
|
|
236
248
|
}
|
|
237
|
-
this.
|
|
249
|
+
this.logger.info("no mocked response received!");
|
|
238
250
|
this.once("response-internal", (message) => {
|
|
239
|
-
this.
|
|
240
|
-
this.
|
|
241
|
-
this.
|
|
251
|
+
this.logger.info(message.statusCode, message.statusMessage);
|
|
252
|
+
this.logger.info("original response headers:", message.headers);
|
|
253
|
+
this.logger.info('emitting the custom "response" event...');
|
|
242
254
|
this.emitter.emit(
|
|
243
255
|
"response",
|
|
244
256
|
createResponse(message),
|
|
@@ -251,29 +263,31 @@ var _NodeClientRequest = class extends ClientRequest {
|
|
|
251
263
|
return this;
|
|
252
264
|
}
|
|
253
265
|
emit(event, ...data) {
|
|
254
|
-
this.
|
|
266
|
+
this.logger.info("emit: %s", event);
|
|
255
267
|
if (event === "response") {
|
|
256
|
-
this.
|
|
268
|
+
this.logger.info('found "response" event, cloning the response...');
|
|
257
269
|
try {
|
|
258
270
|
const response = data[0];
|
|
259
271
|
const firstClone = cloneIncomingMessage(response);
|
|
260
272
|
const secondClone = cloneIncomingMessage(response);
|
|
261
273
|
this.emit("response-internal", secondClone);
|
|
262
|
-
this.
|
|
274
|
+
this.logger.info(
|
|
275
|
+
'response successfully cloned, emitting "response" event...'
|
|
276
|
+
);
|
|
263
277
|
return super.emit(event, firstClone, ...data.slice(1));
|
|
264
278
|
} catch (error) {
|
|
265
|
-
this.
|
|
279
|
+
this.logger.info("error when cloning response:", error);
|
|
266
280
|
return super.emit(event, ...data);
|
|
267
281
|
}
|
|
268
282
|
}
|
|
269
283
|
if (event === "error") {
|
|
270
284
|
const error = data[0];
|
|
271
285
|
const errorCode = error.code || "";
|
|
272
|
-
this.
|
|
286
|
+
this.logger.info("error:\n", error);
|
|
273
287
|
if (this.responseSource === "mock" && _NodeClientRequest.suppressErrorCodes.includes(errorCode)) {
|
|
274
288
|
if (!this.capturedError) {
|
|
275
289
|
this.capturedError = error;
|
|
276
|
-
this.
|
|
290
|
+
this.logger.info("captured the first error:", this.capturedError);
|
|
277
291
|
}
|
|
278
292
|
return false;
|
|
279
293
|
}
|
|
@@ -286,7 +300,7 @@ var _NodeClientRequest = class extends ClientRequest {
|
|
|
286
300
|
this.emit("error", this.capturedError);
|
|
287
301
|
return this;
|
|
288
302
|
}
|
|
289
|
-
this.
|
|
303
|
+
this.logger.info("writing request chunks...", this.chunks);
|
|
290
304
|
for (const { chunk: chunk2, encoding: encoding2 } of this.chunks) {
|
|
291
305
|
if (encoding2) {
|
|
292
306
|
super.write(chunk2, encoding2);
|
|
@@ -295,20 +309,20 @@ var _NodeClientRequest = class extends ClientRequest {
|
|
|
295
309
|
}
|
|
296
310
|
}
|
|
297
311
|
this.once("error", (error) => {
|
|
298
|
-
this.
|
|
312
|
+
this.logger.info("original request error:", error);
|
|
299
313
|
});
|
|
300
314
|
this.once("abort", () => {
|
|
301
|
-
this.
|
|
315
|
+
this.logger.info("original request aborted!");
|
|
302
316
|
});
|
|
303
317
|
this.once("response-internal", (message) => {
|
|
304
|
-
this.
|
|
305
|
-
this.
|
|
318
|
+
this.logger.info(message.statusCode, message.statusMessage);
|
|
319
|
+
this.logger.info("original response headers:", message.headers);
|
|
306
320
|
});
|
|
307
|
-
this.
|
|
321
|
+
this.logger.info("performing original request...");
|
|
308
322
|
return super.end(...[chunk, encoding, callback].filter(Boolean));
|
|
309
323
|
}
|
|
310
324
|
respondWith(mockedResponse) {
|
|
311
|
-
this.
|
|
325
|
+
this.logger.info("responding with a mocked response...", mockedResponse);
|
|
312
326
|
const { status, statusText, headers, body } = mockedResponse;
|
|
313
327
|
this.response.statusCode = status;
|
|
314
328
|
this.response.statusMessage = statusText;
|
|
@@ -321,14 +335,14 @@ var _NodeClientRequest = class extends ClientRequest {
|
|
|
321
335
|
this.response.headers[insensitiveHeaderName] = prevHeaders ? Array.prototype.concat([], prevHeaders, headerValue) : headerValue;
|
|
322
336
|
});
|
|
323
337
|
}
|
|
324
|
-
this.
|
|
338
|
+
this.logger.info("mocked response headers ready:", headers);
|
|
325
339
|
const isResponseStreamRead = new DeferredPromise();
|
|
326
340
|
const closeResponseStream = () => {
|
|
327
|
-
this.
|
|
341
|
+
this.logger.info("closing response stream...");
|
|
328
342
|
this.response.push(null);
|
|
329
343
|
this.response.complete = true;
|
|
330
344
|
isResponseStreamRead.resolve();
|
|
331
|
-
this.
|
|
345
|
+
this.logger.info("closed response stream!");
|
|
332
346
|
};
|
|
333
347
|
if (body) {
|
|
334
348
|
const bodyReader = body.getReader();
|
|
@@ -378,6 +392,7 @@ import {
|
|
|
378
392
|
Agent as HttpsAgent,
|
|
379
393
|
globalAgent as httpsGlobalAgent
|
|
380
394
|
} from "https";
|
|
395
|
+
import { Logger as Logger5 } from "@open-draft/logger";
|
|
381
396
|
|
|
382
397
|
// src/utils/getRequestOptionsByUrl.ts
|
|
383
398
|
function getRequestOptionsByUrl(url) {
|
|
@@ -399,7 +414,8 @@ function getRequestOptionsByUrl(url) {
|
|
|
399
414
|
|
|
400
415
|
// src/utils/getUrlByRequestOptions.ts
|
|
401
416
|
import { Agent } from "http";
|
|
402
|
-
|
|
417
|
+
import { Logger as Logger3 } from "@open-draft/logger";
|
|
418
|
+
var logger3 = new Logger3("utils getUrlByRequestOptions");
|
|
403
419
|
var DEFAULT_PATH = "/";
|
|
404
420
|
var DEFAULT_PROTOCOL = "http:";
|
|
405
421
|
var DEFAULT_HOST = "localhost";
|
|
@@ -467,51 +483,52 @@ function getHostname(host, port) {
|
|
|
467
483
|
return `${host}${portString}`;
|
|
468
484
|
}
|
|
469
485
|
function getUrlByRequestOptions(options) {
|
|
470
|
-
|
|
486
|
+
logger3.info("request options", options);
|
|
471
487
|
if (options.uri) {
|
|
472
|
-
|
|
488
|
+
logger3.info(
|
|
473
489
|
'constructing url from explicitly provided "options.uri": %s',
|
|
474
490
|
options.uri
|
|
475
491
|
);
|
|
476
492
|
return new URL(options.uri.href);
|
|
477
493
|
}
|
|
478
|
-
|
|
494
|
+
logger3.info("figuring out url from request options...");
|
|
479
495
|
const protocol = getProtocolByRequestOptions(options);
|
|
480
|
-
|
|
496
|
+
logger3.info("protocol", protocol);
|
|
481
497
|
const host = getHostByRequestOptions(options);
|
|
482
|
-
|
|
498
|
+
logger3.info("host", host);
|
|
483
499
|
const port = getPortByRequestOptions(options);
|
|
484
|
-
|
|
500
|
+
logger3.info("port", port);
|
|
485
501
|
const hostname = getHostname(host, port);
|
|
486
|
-
|
|
502
|
+
logger3.info("hostname", hostname);
|
|
487
503
|
const path = options.path || DEFAULT_PATH;
|
|
488
|
-
|
|
504
|
+
logger3.info("path", path);
|
|
489
505
|
const credentials = getAuthByRequestOptions(options);
|
|
490
|
-
|
|
506
|
+
logger3.info("credentials", credentials);
|
|
491
507
|
const authString = credentials ? `${credentials.username}:${credentials.password}@` : "";
|
|
492
|
-
|
|
508
|
+
logger3.info("auth string:", authString);
|
|
493
509
|
const url = new URL(`${protocol}//${authString}${hostname}${path}`);
|
|
494
|
-
|
|
510
|
+
logger3.info("created url:", url);
|
|
495
511
|
return url;
|
|
496
512
|
}
|
|
497
513
|
|
|
498
514
|
// src/utils/cloneObject.ts
|
|
499
|
-
|
|
515
|
+
import { Logger as Logger4 } from "@open-draft/logger";
|
|
516
|
+
var logger4 = new Logger4("cloneObject");
|
|
500
517
|
function isPlainObject(obj) {
|
|
501
518
|
var _a;
|
|
502
|
-
|
|
519
|
+
logger4.info("is plain object?", obj);
|
|
503
520
|
if (obj == null || !((_a = obj.constructor) == null ? void 0 : _a.name)) {
|
|
504
|
-
|
|
521
|
+
logger4.info("given object is undefined, not a plain object...");
|
|
505
522
|
return false;
|
|
506
523
|
}
|
|
507
|
-
|
|
524
|
+
logger4.info("checking the object constructor:", obj.constructor.name);
|
|
508
525
|
return obj.constructor.name === "Object";
|
|
509
526
|
}
|
|
510
527
|
function cloneObject(obj) {
|
|
511
|
-
|
|
528
|
+
logger4.info("cloning object:", obj);
|
|
512
529
|
const enumerableProperties = Object.entries(obj).reduce(
|
|
513
530
|
(acc, [key, value]) => {
|
|
514
|
-
|
|
531
|
+
logger4.info("analyzing key-value pair:", key, value);
|
|
515
532
|
acc[key] = isPlainObject(value) ? cloneObject(value) : value;
|
|
516
533
|
return acc;
|
|
517
534
|
},
|
|
@@ -526,25 +543,25 @@ function isObject(value) {
|
|
|
526
543
|
}
|
|
527
544
|
|
|
528
545
|
// src/interceptors/ClientRequest/utils/normalizeClientRequestArgs.ts
|
|
529
|
-
var
|
|
546
|
+
var logger5 = new Logger5("http normalizeClientRequestArgs");
|
|
530
547
|
function resolveRequestOptions(args, url) {
|
|
531
548
|
if (typeof args[1] === "undefined" || typeof args[1] === "function") {
|
|
532
|
-
|
|
549
|
+
logger5.info("request options not provided, deriving from the url", url);
|
|
533
550
|
return getRequestOptionsByUrl(url);
|
|
534
551
|
}
|
|
535
552
|
if (args[1]) {
|
|
536
|
-
|
|
553
|
+
logger5.info("has custom RequestOptions!", args[1]);
|
|
537
554
|
const requestOptionsFromUrl = getRequestOptionsByUrl(url);
|
|
538
|
-
|
|
539
|
-
|
|
555
|
+
logger5.info("derived RequestOptions from the URL:", requestOptionsFromUrl);
|
|
556
|
+
logger5.info("cloning RequestOptions...");
|
|
540
557
|
const clonedRequestOptions = cloneObject(args[1]);
|
|
541
|
-
|
|
558
|
+
logger5.info("successfully cloned RequestOptions!", clonedRequestOptions);
|
|
542
559
|
return {
|
|
543
560
|
...requestOptionsFromUrl,
|
|
544
561
|
...clonedRequestOptions
|
|
545
562
|
};
|
|
546
563
|
}
|
|
547
|
-
|
|
564
|
+
logger5.info("using an empty object as request options");
|
|
548
565
|
return {};
|
|
549
566
|
}
|
|
550
567
|
function resolveCallback(args) {
|
|
@@ -554,28 +571,28 @@ function normalizeClientRequestArgs(defaultProtocol, ...args) {
|
|
|
554
571
|
let url;
|
|
555
572
|
let options;
|
|
556
573
|
let callback;
|
|
557
|
-
|
|
558
|
-
|
|
574
|
+
logger5.info("arguments", args);
|
|
575
|
+
logger5.info("using default protocol:", defaultProtocol);
|
|
559
576
|
if (typeof args[0] === "string") {
|
|
560
|
-
|
|
577
|
+
logger5.info("first argument is a location string:", args[0]);
|
|
561
578
|
url = new URL(args[0]);
|
|
562
|
-
|
|
579
|
+
logger5.info("created a url:", url);
|
|
563
580
|
const requestOptionsFromUrl = getRequestOptionsByUrl(url);
|
|
564
|
-
|
|
581
|
+
logger5.info("request options from url:", requestOptionsFromUrl);
|
|
565
582
|
options = resolveRequestOptions(args, url);
|
|
566
|
-
|
|
583
|
+
logger5.info("resolved request options:", options);
|
|
567
584
|
callback = resolveCallback(args);
|
|
568
585
|
} else if (args[0] instanceof URL) {
|
|
569
586
|
url = args[0];
|
|
570
|
-
|
|
587
|
+
logger5.info("first argument is a URL:", url);
|
|
571
588
|
options = resolveRequestOptions(args, url);
|
|
572
|
-
|
|
589
|
+
logger5.info("derived request options:", options);
|
|
573
590
|
callback = resolveCallback(args);
|
|
574
591
|
} else if ("hash" in args[0] && !("method" in args[0])) {
|
|
575
592
|
const [legacyUrl] = args;
|
|
576
|
-
|
|
593
|
+
logger5.info("first argument is a legacy URL:", legacyUrl);
|
|
577
594
|
if (legacyUrl.hostname === null) {
|
|
578
|
-
|
|
595
|
+
logger5.info("given legacy URL is relative (no hostname)");
|
|
579
596
|
return isObject(args[1]) ? normalizeClientRequestArgs(
|
|
580
597
|
defaultProtocol,
|
|
581
598
|
{ path: legacyUrl.path, ...args[1] },
|
|
@@ -586,7 +603,7 @@ function normalizeClientRequestArgs(defaultProtocol, ...args) {
|
|
|
586
603
|
args[1]
|
|
587
604
|
);
|
|
588
605
|
}
|
|
589
|
-
|
|
606
|
+
logger5.info("given legacy url is absolute");
|
|
590
607
|
const resolvedUrl = new URL(legacyUrl.href);
|
|
591
608
|
return args[1] === void 0 ? normalizeClientRequestArgs(defaultProtocol, resolvedUrl) : typeof args[1] === "function" ? normalizeClientRequestArgs(defaultProtocol, resolvedUrl, args[1]) : normalizeClientRequestArgs(
|
|
592
609
|
defaultProtocol,
|
|
@@ -596,11 +613,11 @@ function normalizeClientRequestArgs(defaultProtocol, ...args) {
|
|
|
596
613
|
);
|
|
597
614
|
} else if (isObject(args[0])) {
|
|
598
615
|
options = args[0];
|
|
599
|
-
|
|
616
|
+
logger5.info("first argument is RequestOptions:", options);
|
|
600
617
|
options.protocol = options.protocol || defaultProtocol;
|
|
601
|
-
|
|
618
|
+
logger5.info("normalized request options:", options);
|
|
602
619
|
url = getUrlByRequestOptions(options);
|
|
603
|
-
|
|
620
|
+
logger5.info("created a URL from RequestOptions:", url.href);
|
|
604
621
|
callback = resolveCallback(args);
|
|
605
622
|
} else {
|
|
606
623
|
throw new Error(
|
|
@@ -614,18 +631,18 @@ function normalizeClientRequestArgs(defaultProtocol, ...args) {
|
|
|
614
631
|
rejectUnauthorized: options.rejectUnauthorized
|
|
615
632
|
}) : new HttpAgent();
|
|
616
633
|
options.agent = agent;
|
|
617
|
-
|
|
634
|
+
logger5.info("resolved fallback agent:", agent);
|
|
618
635
|
}
|
|
619
636
|
if (!options._defaultAgent) {
|
|
620
|
-
|
|
637
|
+
logger5.info(
|
|
621
638
|
'has no default agent, setting the default agent for "%s"',
|
|
622
639
|
options.protocol
|
|
623
640
|
);
|
|
624
641
|
options._defaultAgent = options.protocol === "https:" ? httpsGlobalAgent : httpGlobalAgent;
|
|
625
642
|
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
643
|
+
logger5.info("successfully resolved url:", url.href);
|
|
644
|
+
logger5.info("successfully resolved options:", options);
|
|
645
|
+
logger5.info("successfully resolved callback:", callback);
|
|
629
646
|
return [url, options, callback];
|
|
630
647
|
}
|
|
631
648
|
|
|
@@ -643,10 +660,11 @@ function get(protocol, options) {
|
|
|
643
660
|
}
|
|
644
661
|
|
|
645
662
|
// src/interceptors/ClientRequest/http.request.ts
|
|
646
|
-
|
|
663
|
+
import { Logger as Logger6 } from "@open-draft/logger";
|
|
664
|
+
var logger6 = new Logger6("http request");
|
|
647
665
|
function request(protocol, options) {
|
|
648
666
|
return (...args) => {
|
|
649
|
-
|
|
667
|
+
logger6.info('request call (protocol "%s"):', protocol, args);
|
|
650
668
|
const clientRequestArgs = normalizeClientRequestArgs(
|
|
651
669
|
`${protocol}:`,
|
|
652
670
|
...args
|
|
@@ -664,21 +682,21 @@ var _ClientRequestInterceptor = class extends Interceptor {
|
|
|
664
682
|
this.modules.set("https", https);
|
|
665
683
|
}
|
|
666
684
|
setup() {
|
|
667
|
-
const
|
|
685
|
+
const logger7 = this.logger.extend("setup");
|
|
668
686
|
for (const [protocol, requestModule] of this.modules) {
|
|
669
687
|
const { request: pureRequest, get: pureGet } = requestModule;
|
|
670
688
|
this.subscriptions.push(() => {
|
|
671
689
|
requestModule.request = pureRequest;
|
|
672
690
|
requestModule.get = pureGet;
|
|
673
|
-
|
|
691
|
+
logger7.info('native "%s" module restored!', protocol);
|
|
674
692
|
});
|
|
675
693
|
const options = {
|
|
676
694
|
emitter: this.emitter,
|
|
677
|
-
|
|
695
|
+
logger: this.logger
|
|
678
696
|
};
|
|
679
697
|
requestModule.request = request(protocol, options);
|
|
680
698
|
requestModule.get = get(protocol, options);
|
|
681
|
-
|
|
699
|
+
logger7.info('native "%s" module patched!', protocol);
|
|
682
700
|
}
|
|
683
701
|
}
|
|
684
702
|
};
|
package/lib/node/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { E as ExtractEventNames, H as HttpRequestEventMap, I as IS_PATCHED_MODULE, e as Interceptor, a as InterceptorEventMap, c as InterceptorReadyState, b as InterceptorSubscription, R as RequestCredentials, d as deleteGlobalSymbol, g as getGlobalSymbol } from './Interceptor-
|
|
2
|
-
export { a as BatchInterceptor, B as BatchInterceptorOptions, E as ExtractEventMapType } from './BatchInterceptor-
|
|
1
|
+
export { E as ExtractEventNames, H as HttpRequestEventMap, I as IS_PATCHED_MODULE, e as Interceptor, a as InterceptorEventMap, c as InterceptorReadyState, b as InterceptorSubscription, R as RequestCredentials, d as deleteGlobalSymbol, g as getGlobalSymbol } from './Interceptor-f9dfe016.js';
|
|
2
|
+
export { a as BatchInterceptor, B as BatchInterceptorOptions, E as ExtractEventMapType } from './BatchInterceptor-fe69020d.js';
|
|
3
|
+
import '@open-draft/logger';
|
|
3
4
|
import 'strict-event-emitter';
|
|
4
|
-
import 'debug';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Removes query parameters and hashes from a given URL.
|
package/lib/node/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkRJMXHEGJjs = require('./chunk-RJMXHEGJ.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkPKB2CXQVjs = require('./chunk-PKB2CXQV.js');
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
var _chunkVQ4DZOBBjs = require('./chunk-VQ4DZOBB.js');
|
|
@@ -13,7 +13,7 @@ var _chunkVQ4DZOBBjs = require('./chunk-VQ4DZOBB.js');
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _chunk6KJ5M2VRjs = require('./chunk-6KJ5M2VR.js');
|
|
17
17
|
|
|
18
18
|
// src/utils/getCleanUrl.ts
|
|
19
19
|
function getCleanUrl(url, isAbsolute = true) {
|
|
@@ -29,4 +29,4 @@ function getCleanUrl(url, isAbsolute = true) {
|
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
exports.BatchInterceptor =
|
|
32
|
+
exports.BatchInterceptor = _chunkRJMXHEGJjs.BatchInterceptor; exports.IS_PATCHED_MODULE = _chunkVQ4DZOBBjs.IS_PATCHED_MODULE; exports.Interceptor = _chunk6KJ5M2VRjs.Interceptor; exports.InterceptorReadyState = _chunk6KJ5M2VRjs.InterceptorReadyState; exports.decodeBuffer = _chunkPKB2CXQVjs.decodeBuffer; exports.deleteGlobalSymbol = _chunk6KJ5M2VRjs.deleteGlobalSymbol; exports.encodeBuffer = _chunkPKB2CXQVjs.encodeBuffer; exports.getCleanUrl = getCleanUrl; exports.getGlobalSymbol = _chunk6KJ5M2VRjs.getGlobalSymbol;
|
package/lib/node/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BatchInterceptor
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SBAVVQIW.mjs";
|
|
4
4
|
import {
|
|
5
5
|
decodeBuffer,
|
|
6
6
|
encodeBuffer
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-S5A4P4BZ.mjs";
|
|
8
8
|
import {
|
|
9
9
|
IS_PATCHED_MODULE
|
|
10
10
|
} from "./chunk-GFH37L5D.mjs";
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
InterceptorReadyState,
|
|
14
14
|
deleteGlobalSymbol,
|
|
15
15
|
getGlobalSymbol
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-3V5OWTY7.mjs";
|
|
17
17
|
|
|
18
18
|
// src/utils/getCleanUrl.ts
|
|
19
19
|
function getCleanUrl(url, isAbsolute = true) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import http from 'http';
|
|
2
2
|
import https from 'https';
|
|
3
|
-
import { A as AsyncEventEmitter, H as HttpRequestEventMap, e as Interceptor } from '../../Interceptor-
|
|
3
|
+
import { A as AsyncEventEmitter, H as HttpRequestEventMap, e as Interceptor } from '../../Interceptor-f9dfe016.js';
|
|
4
|
+
import '@open-draft/logger';
|
|
4
5
|
import 'strict-event-emitter';
|
|
5
|
-
import 'debug';
|
|
6
6
|
|
|
7
7
|
type Protocol = 'http' | 'https';
|
|
8
8
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk7XU7Q63Wjs = require('../../chunk-7XU7Q63W.js');
|
|
4
4
|
require('../../chunk-ZJOF5MEZ.js');
|
|
5
|
-
require('../../chunk-
|
|
5
|
+
require('../../chunk-6KJ5M2VR.js');
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
exports.ClientRequestInterceptor =
|
|
8
|
+
exports.ClientRequestInterceptor = _chunk7XU7Q63Wjs.ClientRequestInterceptor;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ClientRequestInterceptor
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-XVHIXGXD.mjs";
|
|
4
4
|
import "../../chunk-STA6QBYM.mjs";
|
|
5
|
-
import "../../chunk-
|
|
5
|
+
import "../../chunk-3V5OWTY7.mjs";
|
|
6
6
|
export {
|
|
7
7
|
ClientRequestInterceptor
|
|
8
8
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { f as InteractiveRequest, A as AsyncEventEmitter, H as HttpRequestEventMap, e as Interceptor } from '../../Interceptor-
|
|
1
|
+
import { f as InteractiveRequest, A as AsyncEventEmitter, H as HttpRequestEventMap, e as Interceptor } from '../../Interceptor-f9dfe016.js';
|
|
2
|
+
import '@open-draft/logger';
|
|
2
3
|
import 'strict-event-emitter';
|
|
3
|
-
import 'debug';
|
|
4
4
|
|
|
5
5
|
type XMLHttpRequestEventListener = (request: InteractiveRequest, requestId: string) => Promise<void> | void;
|
|
6
6
|
type XMLHttpRequestEmitter = AsyncEventEmitter<HttpRequestEventMap>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../../chunk-
|
|
3
|
+
var _chunk2OJRZCGSjs = require('../../chunk-2OJRZCGS.js');
|
|
4
|
+
require('../../chunk-PKB2CXQV.js');
|
|
5
5
|
require('../../chunk-VQ4DZOBB.js');
|
|
6
6
|
require('../../chunk-ZJOF5MEZ.js');
|
|
7
|
-
require('../../chunk-
|
|
7
|
+
require('../../chunk-6KJ5M2VR.js');
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
exports.XMLHttpRequestInterceptor =
|
|
10
|
+
exports.XMLHttpRequestInterceptor = _chunk2OJRZCGSjs.XMLHttpRequestInterceptor;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
XMLHttpRequestInterceptor
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-
|
|
3
|
+
} from "../../chunk-RL5IV5PL.mjs";
|
|
4
|
+
import "../../chunk-S5A4P4BZ.mjs";
|
|
5
5
|
import "../../chunk-GFH37L5D.mjs";
|
|
6
6
|
import "../../chunk-STA6QBYM.mjs";
|
|
7
|
-
import "../../chunk-
|
|
7
|
+
import "../../chunk-3V5OWTY7.mjs";
|
|
8
8
|
export {
|
|
9
9
|
XMLHttpRequestInterceptor
|
|
10
10
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { e as Interceptor, H as HttpRequestEventMap } from '../../Interceptor-
|
|
1
|
+
import { e as Interceptor, H as HttpRequestEventMap } from '../../Interceptor-f9dfe016.js';
|
|
2
|
+
import '@open-draft/logger';
|
|
2
3
|
import 'strict-event-emitter';
|
|
3
|
-
import 'debug';
|
|
4
4
|
|
|
5
5
|
declare class FetchInterceptor extends Interceptor<HttpRequestEventMap> {
|
|
6
6
|
static symbol: symbol;
|