@depup/mswjs__interceptors 0.42.1-depup.0 → 0.42.3-depup.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/README.md +2 -2
- package/changes.json +1 -1
- package/lib/node/{has-configurable-global-CJCh_g1I.js → has-configurable-global-BU1sT1u4.js} +2 -2
- package/lib/node/{has-configurable-global-CJCh_g1I.js.map → has-configurable-global-BU1sT1u4.js.map} +1 -1
- package/lib/node/interceptors/ClientRequest/index.js +2 -2
- package/lib/node/interceptors/XMLHttpRequest/node.js +3 -3
- package/lib/node/interceptors/fetch/node.js +3 -3
- package/lib/node/interceptors/http/index.js +1 -1
- package/lib/node/interceptors/net/index.d.ts +39 -1
- package/lib/node/interceptors/net/index.js +1 -1
- package/lib/node/{net-DtMnyEeg.js → net-Ca8p1rIe.js} +138 -9
- package/lib/node/net-Ca8p1rIe.js.map +1 -0
- package/lib/node/remote-http-interceptor.js +1 -1
- package/lib/node/{source-lP0yyEtA.js → source-CIgPng7r.js} +37 -5
- package/lib/node/source-CIgPng7r.js.map +1 -0
- package/package.json +3 -3
- package/src/interceptors/http/http-parser.ts +13 -1
- package/src/interceptors/http/source.ts +37 -3
- package/src/interceptors/net/index.ts +16 -15
- package/src/interceptors/net/socket-controller.ts +183 -2
- package/lib/node/net-DtMnyEeg.js.map +0 -1
- package/lib/node/source-lP0yyEtA.js.map +0 -1
package/README.md
CHANGED
|
@@ -13,8 +13,8 @@ npm install @depup/mswjs__interceptors
|
|
|
13
13
|
|
|
14
14
|
| Field | Value |
|
|
15
15
|
|-------|-------|
|
|
16
|
-
| Original | [@mswjs/interceptors](https://www.npmjs.com/package/@mswjs/interceptors) @ 0.42.
|
|
17
|
-
| Processed | 2026-07-
|
|
16
|
+
| Original | [@mswjs/interceptors](https://www.npmjs.com/package/@mswjs/interceptors) @ 0.42.3 |
|
|
17
|
+
| Processed | 2026-07-24 |
|
|
18
18
|
| Smoke test | passed |
|
|
19
19
|
| Deps updated | 0 |
|
|
20
20
|
|
package/changes.json
CHANGED
package/lib/node/{has-configurable-global-CJCh_g1I.js → has-configurable-global-BU1sT1u4.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as getDeepPropertyDescriptor } from "./net-
|
|
1
|
+
import { a as getDeepPropertyDescriptor } from "./net-Ca8p1rIe.js";
|
|
2
2
|
//#region src/utils/has-configurable-global.ts
|
|
3
3
|
/**
|
|
4
4
|
* Returns a boolean indicating whether the given global property
|
|
@@ -19,4 +19,4 @@ function hasConfigurableGlobal(propertyName) {
|
|
|
19
19
|
//#endregion
|
|
20
20
|
export { hasConfigurableGlobal as t };
|
|
21
21
|
|
|
22
|
-
//# sourceMappingURL=has-configurable-global-
|
|
22
|
+
//# sourceMappingURL=has-configurable-global-BU1sT1u4.js.map
|
package/lib/node/{has-configurable-global-CJCh_g1I.js.map → has-configurable-global-BU1sT1u4.js.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"has-configurable-global-
|
|
1
|
+
{"version":3,"file":"has-configurable-global-BU1sT1u4.js","names":[],"sources":["../../src/utils/has-configurable-global.ts"],"sourcesContent":["import { getDeepPropertyDescriptor } from './patches-registry'\n\n/**\n * Returns a boolean indicating whether the given global property\n * is defined and is configurable.\n */\nexport function hasConfigurableGlobal(propertyName: string): boolean {\n const match = getDeepPropertyDescriptor(globalThis, propertyName)\n\n // The property is not set at all.\n if (typeof match === 'undefined') {\n return false\n }\n\n const { descriptor } = match\n\n // The property is set to a getter that returns undefined.\n if (\n typeof descriptor.get === 'function' &&\n typeof descriptor.get() === 'undefined'\n ) {\n return false\n }\n\n // The property is set to a value equal to undefined.\n if (typeof descriptor.get === 'undefined' && descriptor.value == null) {\n return false\n }\n\n if (typeof descriptor.set === 'undefined' && !descriptor.configurable) {\n console.error(\n `[MSW] Failed to apply interceptor: the global \\`${propertyName}\\` property is non-configurable. This is likely an issue with your environment. If you are using a framework, please open an issue about this in their repository.`\n )\n return false\n }\n\n return true\n}\n"],"mappings":";;;;;;AAMA,SAAgB,sBAAsB,cAA+B;CACnE,MAAM,QAAQ,0BAA0B,YAAY,YAAY;CAGhE,IAAI,OAAO,UAAU,aACnB,OAAO;CAGT,MAAM,EAAE,eAAe;CAGvB,IACE,OAAO,WAAW,QAAQ,cAC1B,OAAO,WAAW,IAAI,MAAM,aAE5B,OAAO;CAIT,IAAI,OAAO,WAAW,QAAQ,eAAe,WAAW,SAAS,MAC/D,OAAO;CAGT,IAAI,OAAO,WAAW,QAAQ,eAAe,CAAC,WAAW,cAAc;EACrE,QAAQ,MACN,mDAAmD,aAAa,mKAClE;EACA,OAAO;CACT;CAEA,OAAO;AACT"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as forwardHttpEvents, o as runInRequestContext, t as NodeHttpRequestSource } from "../../source-
|
|
1
|
+
import { i as forwardHttpEvents, o as runInRequestContext, t as NodeHttpRequestSource } from "../../source-CIgPng7r.js";
|
|
2
2
|
import { i as Interceptor } from "../../buffer-utils-BvPY1Tc-.js";
|
|
3
|
-
import { o as patchesRegistry } from "../../net-
|
|
3
|
+
import { o as patchesRegistry } from "../../net-Ca8p1rIe.js";
|
|
4
4
|
import http from "node:http";
|
|
5
5
|
import https from "node:https";
|
|
6
6
|
//#region src/interceptors/ClientRequest/index.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { a as requestContext, i as forwardHttpEvents, t as NodeHttpRequestSource } from "../../source-
|
|
1
|
+
import { a as requestContext, i as forwardHttpEvents, t as NodeHttpRequestSource } from "../../source-CIgPng7r.js";
|
|
2
2
|
import { a as createLogger, i as Interceptor } from "../../buffer-utils-BvPY1Tc-.js";
|
|
3
3
|
import { t as FetchRequest } from "../../fetch-utils-Dw1PsmtX.js";
|
|
4
|
-
import { o as patchesRegistry } from "../../net-
|
|
5
|
-
import { t as hasConfigurableGlobal } from "../../has-configurable-global-
|
|
4
|
+
import { o as patchesRegistry } from "../../net-Ca8p1rIe.js";
|
|
5
|
+
import { t as hasConfigurableGlobal } from "../../has-configurable-global-BU1sT1u4.js";
|
|
6
6
|
//#region src/interceptors/XMLHttpRequest/node.ts
|
|
7
7
|
const logger = createLogger("xhr");
|
|
8
8
|
var XMLHttpRequestInterceptor = class extends Interceptor {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { a as requestContext, i as forwardHttpEvents, t as NodeHttpRequestSource } from "../../source-
|
|
1
|
+
import { a as requestContext, i as forwardHttpEvents, t as NodeHttpRequestSource } from "../../source-CIgPng7r.js";
|
|
2
2
|
import { i as Interceptor } from "../../buffer-utils-BvPY1Tc-.js";
|
|
3
3
|
import { i as getErrorResponse } from "../../fetch-utils-Dw1PsmtX.js";
|
|
4
|
-
import { o as patchesRegistry } from "../../net-
|
|
5
|
-
import { t as hasConfigurableGlobal } from "../../has-configurable-global-
|
|
4
|
+
import { o as patchesRegistry } from "../../net-Ca8p1rIe.js";
|
|
5
|
+
import { t as hasConfigurableGlobal } from "../../has-configurable-global-BU1sT1u4.js";
|
|
6
6
|
//#region src/interceptors/fetch/node.ts
|
|
7
7
|
/**
|
|
8
8
|
* Interceptor for `fetch` requests in Node.js.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as forwardHttpEvents, t as NodeHttpRequestSource } from "../../source-
|
|
1
|
+
import { i as forwardHttpEvents, t as NodeHttpRequestSource } from "../../source-CIgPng7r.js";
|
|
2
2
|
import { i as Interceptor } from "../../buffer-utils-BvPY1Tc-.js";
|
|
3
3
|
//#region src/interceptors/http/index.ts
|
|
4
4
|
/**
|
|
@@ -103,6 +103,7 @@ interface TcpWrap {
|
|
|
103
103
|
oncomplete: (status: OperationStatus, owner: TcpHandle, request: TcpWrap, readable?: boolean, writable?: boolean) => void;
|
|
104
104
|
}
|
|
105
105
|
declare abstract class SocketController {
|
|
106
|
+
#private;
|
|
106
107
|
static PENDING: 0;
|
|
107
108
|
static CLAIMED: 1;
|
|
108
109
|
static PASSTHROUGH: 2;
|
|
@@ -119,6 +120,22 @@ declare abstract class SocketController {
|
|
|
119
120
|
* Establish this socket connection as-is.
|
|
120
121
|
*/
|
|
121
122
|
passthrough(): void;
|
|
123
|
+
/**
|
|
124
|
+
* Await a verdict on this connection from the given number of
|
|
125
|
+
* subscribers. A connection nobody awaits to inspect (or one that
|
|
126
|
+
* every awaited subscriber has declined) is passed through as-is.
|
|
127
|
+
* This makes "unclaimed after everyone declined" a state owned by
|
|
128
|
+
* the controller instead of the individual subscribers.
|
|
129
|
+
*/
|
|
130
|
+
awaitVerdicts(count: number): void;
|
|
131
|
+
/**
|
|
132
|
+
* Decline this socket connection. Declining means the subscriber
|
|
133
|
+
* has inspected the connection and will not handle it (e.g. the
|
|
134
|
+
* traffic is not of the protocol that subscriber implements).
|
|
135
|
+
* Once every awaited subscriber declines, the connection is
|
|
136
|
+
* passed through as-is.
|
|
137
|
+
*/
|
|
138
|
+
decline(): void;
|
|
122
139
|
}
|
|
123
140
|
type FlushPendingDataFunction = (data: NonNullable<net.Socket['_pendingData']>, encoding: BufferEncoding | undefined, callback: (data: NonNullable<net.Socket['_pendingData']>) => void) => void;
|
|
124
141
|
declare class TcpSocketController extends SocketController {
|
|
@@ -133,8 +150,29 @@ declare class TcpSocketController extends SocketController {
|
|
|
133
150
|
* on this socket can be handled anew. This is meant for kept-alive
|
|
134
151
|
* sockets that are reused for multiple exchanges by clients that
|
|
135
152
|
* don't emit the "free" event on the socket (e.g. Undici).
|
|
153
|
+
*
|
|
154
|
+
* Providing connection options retargets this connection: the
|
|
155
|
+
* exchanges that follow belong to the given target (e.g. the
|
|
156
|
+
* authority of an established "CONNECT" tunnel). An unclaimed
|
|
157
|
+
* exchange then passes through to that target instead of the
|
|
158
|
+
* originally dialed one, and a claimed exchange reports it as the
|
|
159
|
+
* peer. The verdict count is deliberately not re-armed: subscribers
|
|
160
|
+
* that declined this connection's protocol stay declined across
|
|
161
|
+
* the exchanges, retargeted or not.
|
|
162
|
+
*/
|
|
163
|
+
reset(connectionOptions?: NetworkConnectionOptions & net.SocketConnectOpts): void;
|
|
164
|
+
/**
|
|
165
|
+
* Schedule a reset of this controller to happen right before the
|
|
166
|
+
* next client write. The consumer signals the boundary of the
|
|
167
|
+
* current exchange (e.g. an HTTP message boundary) the moment it is
|
|
168
|
+
* parsed — mid-delivery of the exchange's final chunk — when an
|
|
169
|
+
* immediate reset would discard that chunk. Deferring the reset to
|
|
170
|
+
* the next write lets the current exchange settle as-is while the
|
|
171
|
+
* next exchange's first write already buffers for a new verdict
|
|
172
|
+
* (instead of following the previous one, e.g. leaking to the
|
|
173
|
+
* passthrough connection).
|
|
136
174
|
*/
|
|
137
|
-
|
|
175
|
+
scheduleReset(): void;
|
|
138
176
|
protected emulateConnect(): void;
|
|
139
177
|
/**
|
|
140
178
|
* Suspend forwarding of the passthrough socket events ("data", "end", "close")
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as SocketInterceptor } from "../../net-
|
|
1
|
+
import { t as SocketInterceptor } from "../../net-Ca8p1rIe.js";
|
|
2
2
|
export { SocketInterceptor };
|
|
@@ -381,6 +381,7 @@ var SocketController = class SocketController {
|
|
|
381
381
|
static {
|
|
382
382
|
this.PASSTHROUGH = 2;
|
|
383
383
|
}
|
|
384
|
+
#awaitedVerdicts = 0;
|
|
384
385
|
constructor(socket) {
|
|
385
386
|
this[kRawSocket] = socket;
|
|
386
387
|
socket[kPatched] = true;
|
|
@@ -402,15 +403,51 @@ var SocketController = class SocketController {
|
|
|
402
403
|
invariant(this.readyState === SocketController.PENDING, "Failed to passthrough a socket connection: already handled (%s)", this.readyState);
|
|
403
404
|
this.readyState = SocketController.PASSTHROUGH;
|
|
404
405
|
}
|
|
406
|
+
/**
|
|
407
|
+
* Await a verdict on this connection from the given number of
|
|
408
|
+
* subscribers. A connection nobody awaits to inspect (or one that
|
|
409
|
+
* every awaited subscriber has declined) is passed through as-is.
|
|
410
|
+
* This makes "unclaimed after everyone declined" a state owned by
|
|
411
|
+
* the controller instead of the individual subscribers.
|
|
412
|
+
*/
|
|
413
|
+
awaitVerdicts(count) {
|
|
414
|
+
this.#awaitedVerdicts = count;
|
|
415
|
+
if (this.#awaitedVerdicts === 0) this.passthrough();
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Decline this socket connection. Declining means the subscriber
|
|
419
|
+
* has inspected the connection and will not handle it (e.g. the
|
|
420
|
+
* traffic is not of the protocol that subscriber implements).
|
|
421
|
+
* Once every awaited subscriber declines, the connection is
|
|
422
|
+
* passed through as-is.
|
|
423
|
+
*/
|
|
424
|
+
decline() {
|
|
425
|
+
if (this.readyState !== SocketController.PENDING) return;
|
|
426
|
+
this.#awaitedVerdicts -= 1;
|
|
427
|
+
if (this.#awaitedVerdicts <= 0)
|
|
428
|
+
/**
|
|
429
|
+
* @note Defer the passthrough so it never transitions this
|
|
430
|
+
* controller in the middle of a client write. Declines are
|
|
431
|
+
* issued while the written data is being pushed to the server
|
|
432
|
+
* socket, and a synchronous transition would race the write's
|
|
433
|
+
* own bookkeeping (e.g. re-buffering the write after a reset
|
|
434
|
+
* at an exchange boundary).
|
|
435
|
+
*/
|
|
436
|
+
process.nextTick(() => {
|
|
437
|
+
if (this.readyState === SocketController.PENDING && !this[kRawSocket].destroyed) this.passthrough();
|
|
438
|
+
});
|
|
439
|
+
}
|
|
405
440
|
};
|
|
406
441
|
var TcpSocketController = class extends SocketController {
|
|
407
442
|
#connectionOptions;
|
|
443
|
+
#retargetedConnectionOptions;
|
|
408
444
|
#realWriteGeneric;
|
|
409
445
|
#passthroughSocket = null;
|
|
410
446
|
#bufferedWrites = [];
|
|
411
447
|
#readsCorked = false;
|
|
412
448
|
#corkedReads = [];
|
|
413
449
|
#realHandleSwapped = false;
|
|
450
|
+
#resetScheduled = false;
|
|
414
451
|
#clientCloseEmitted = false;
|
|
415
452
|
#clientEndPushed = false;
|
|
416
453
|
#connectEmulated = false;
|
|
@@ -492,8 +529,39 @@ var TcpSocketController = class extends SocketController {
|
|
|
492
529
|
* on this socket can be handled anew. This is meant for kept-alive
|
|
493
530
|
* sockets that are reused for multiple exchanges by clients that
|
|
494
531
|
* don't emit the "free" event on the socket (e.g. Undici).
|
|
532
|
+
*
|
|
533
|
+
* Providing connection options retargets this connection: the
|
|
534
|
+
* exchanges that follow belong to the given target (e.g. the
|
|
535
|
+
* authority of an established "CONNECT" tunnel). An unclaimed
|
|
536
|
+
* exchange then passes through to that target instead of the
|
|
537
|
+
* originally dialed one, and a claimed exchange reports it as the
|
|
538
|
+
* peer. The verdict count is deliberately not re-armed: subscribers
|
|
539
|
+
* that declined this connection's protocol stay declined across
|
|
540
|
+
* the exchanges, retargeted or not.
|
|
495
541
|
*/
|
|
496
|
-
reset() {
|
|
542
|
+
reset(connectionOptions) {
|
|
543
|
+
if (connectionOptions != null) {
|
|
544
|
+
this.#retargetedConnectionOptions = connectionOptions;
|
|
545
|
+
this.#connectionOptions = connectionOptions;
|
|
546
|
+
/**
|
|
547
|
+
* @note The passthrough connection to the original target, if
|
|
548
|
+
* any, cannot serve the retargeted exchanges. Detach its
|
|
549
|
+
* forwarding listeners before destroying it so its teardown is
|
|
550
|
+
* not mistaken for the client connection's own (e.g. its "close"
|
|
551
|
+
* must not close the client socket).
|
|
552
|
+
*/
|
|
553
|
+
if (this.#passthroughSocket) {
|
|
554
|
+
this.#passthroughSocket.removeListener("connect", this.#onRealSocketConnect).removeListener("connectionAttemptFailed", this.#onRealSocketConnectionAttemptFailed).removeListener("connectionAttemptTimeout", this.#onRealSocketConnectionAttemptTimeout).removeListener("data", this.#onRealSocketData).removeListener("error", this.#onRealSocketError).removeListener("end", this.#onRealSocketEnd).removeListener("close", this.#onRealSocketClose).destroy();
|
|
555
|
+
this.#passthroughSocket = null;
|
|
556
|
+
/**
|
|
557
|
+
* @note The handle swapped in from the destroyed connection,
|
|
558
|
+
* if any, no longer carries this socket's traffic. Treat the
|
|
559
|
+
* socket as not swapped so the retargeted passthrough writes
|
|
560
|
+
* directly to the new connection until its own handle swap.
|
|
561
|
+
*/
|
|
562
|
+
this.#realHandleSwapped = false;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
497
565
|
/**
|
|
498
566
|
* @note Only settled (claimed or passed-through) sockets need a reset.
|
|
499
567
|
* Resetting a pending socket again would discard the writes already
|
|
@@ -503,8 +571,23 @@ var TcpSocketController = class extends SocketController {
|
|
|
503
571
|
if (this.readyState === SocketController.PENDING) return;
|
|
504
572
|
this.#reset();
|
|
505
573
|
}
|
|
574
|
+
/**
|
|
575
|
+
* Schedule a reset of this controller to happen right before the
|
|
576
|
+
* next client write. The consumer signals the boundary of the
|
|
577
|
+
* current exchange (e.g. an HTTP message boundary) the moment it is
|
|
578
|
+
* parsed — mid-delivery of the exchange's final chunk — when an
|
|
579
|
+
* immediate reset would discard that chunk. Deferring the reset to
|
|
580
|
+
* the next write lets the current exchange settle as-is while the
|
|
581
|
+
* next exchange's first write already buffers for a new verdict
|
|
582
|
+
* (instead of following the previous one, e.g. leaking to the
|
|
583
|
+
* passthrough connection).
|
|
584
|
+
*/
|
|
585
|
+
scheduleReset() {
|
|
586
|
+
this.#resetScheduled = true;
|
|
587
|
+
}
|
|
506
588
|
#reset() {
|
|
507
589
|
logger$1.verbose("resetting the socket...");
|
|
590
|
+
this.#resetScheduled = false;
|
|
508
591
|
this.readyState = SocketController.PENDING;
|
|
509
592
|
this.pendingConnection = Promise.withResolvers();
|
|
510
593
|
this.#bufferedWrites = [];
|
|
@@ -555,6 +638,13 @@ var TcpSocketController = class extends SocketController {
|
|
|
555
638
|
const data = args[1];
|
|
556
639
|
logger$1.verbose("socket write (state: %d) %o", this.readyState, args);
|
|
557
640
|
/**
|
|
641
|
+
* @note A scheduled reset marks the boundary of the previous
|
|
642
|
+
* exchange (see "scheduleReset"). This write is the first one past
|
|
643
|
+
* the boundary; reset before dispatching so it opens the next
|
|
644
|
+
* exchange instead of following the previous exchange's verdict.
|
|
645
|
+
*/
|
|
646
|
+
if (this.#resetScheduled) this.reset();
|
|
647
|
+
/**
|
|
558
648
|
* @note Buffer the write BEFORE pushing the data to the server socket.
|
|
559
649
|
* Handling the pushed data may transition this controller within the
|
|
560
650
|
* same call stack, and each transition settles the buffered entry:
|
|
@@ -832,6 +922,16 @@ var TcpSocketController = class extends SocketController {
|
|
|
832
922
|
this.#passthroughSocket?.resume();
|
|
833
923
|
};
|
|
834
924
|
/**
|
|
925
|
+
* Forward the client's half-close to the passthrough socket.
|
|
926
|
+
* The client's writable side may finish before the real handle is
|
|
927
|
+
* swapped in ("_final" of a connected client runs against the mock
|
|
928
|
+
* handle), leaving the FIN unsent. Once the handle is swapped, the
|
|
929
|
+
* client's own shutdown reaches the real connection natively.
|
|
930
|
+
*/
|
|
931
|
+
#forwardClientFinish = () => {
|
|
932
|
+
if (!this.#realHandleSwapped) this.#passthroughSocket?.end();
|
|
933
|
+
};
|
|
934
|
+
/**
|
|
835
935
|
* Suspend forwarding of the passthrough socket events ("data", "end", "close")
|
|
836
936
|
* to the client socket. The events are buffered in order until `uncorkReads()`
|
|
837
937
|
* is called. This allows the consumer to delay the delivery of the original
|
|
@@ -931,7 +1031,7 @@ var TcpSocketController = class extends SocketController {
|
|
|
931
1031
|
super.passthrough();
|
|
932
1032
|
logger$1.verbose("-> passthrough!");
|
|
933
1033
|
const createRealSocket = () => {
|
|
934
|
-
const realSocket = this.createConnection();
|
|
1034
|
+
const realSocket = this.#retargetedConnectionOptions ? this.#createRetargetedConnection(this.#retargetedConnectionOptions) : this.createConnection();
|
|
935
1035
|
realSocket[kPatched] = true;
|
|
936
1036
|
if (this.socket.timeout != null) realSocket.setTimeout(this.socket.timeout);
|
|
937
1037
|
return realSocket;
|
|
@@ -964,8 +1064,34 @@ var TcpSocketController = class extends SocketController {
|
|
|
964
1064
|
this.socket.on("drain", this.#onMockSocketDrain);
|
|
965
1065
|
realSocket.removeListener("connect", this.#onRealSocketConnect).removeListener("connectionAttemptFailed", this.#onRealSocketConnectionAttemptFailed).removeListener("connectionAttemptTimeout", this.#onRealSocketConnectionAttemptTimeout).removeListener("data", this.#onRealSocketData).removeListener("error", this.#onRealSocketError).removeListener("end", this.#onRealSocketEnd).removeListener("close", this.#onRealSocketClose);
|
|
966
1066
|
realSocket.once("connect", this.#onRealSocketConnect).on("connectionAttemptFailed", this.#onRealSocketConnectionAttemptFailed).on("connectionAttemptTimeout", this.#onRealSocketConnectionAttemptTimeout).on("data", this.#onRealSocketData).on("error", this.#onRealSocketError).on("end", this.#onRealSocketEnd).on("close", this.#onRealSocketClose);
|
|
1067
|
+
/**
|
|
1068
|
+
* @note Forward the client's half-close, unless the real handle
|
|
1069
|
+
* is already swapped in — the client's own shutdown then reaches
|
|
1070
|
+
* the real connection natively (see "#forwardClientFinish").
|
|
1071
|
+
*/
|
|
1072
|
+
if (!this.#realHandleSwapped) if (this.socket.writableFinished) this.#forwardClientFinish();
|
|
1073
|
+
else {
|
|
1074
|
+
this.socket.removeListener("finish", this.#forwardClientFinish);
|
|
1075
|
+
this.socket.once("finish", this.#forwardClientFinish);
|
|
1076
|
+
}
|
|
967
1077
|
return realSocket;
|
|
968
1078
|
}
|
|
1079
|
+
/**
|
|
1080
|
+
* Create the passthrough connection to the target this controller
|
|
1081
|
+
* was retargeted to (see `reset()`). The original `createConnection`
|
|
1082
|
+
* dials the originally requested target and cannot serve retargeted
|
|
1083
|
+
* exchanges.
|
|
1084
|
+
*/
|
|
1085
|
+
#createRetargetedConnection(connectionOptions) {
|
|
1086
|
+
const realSocket = new net.Socket();
|
|
1087
|
+
/**
|
|
1088
|
+
* @note Mark the socket as patched before connecting: the patched
|
|
1089
|
+
* "Socket.prototype.connect" exempts such sockets, establishing
|
|
1090
|
+
* the connection for real.
|
|
1091
|
+
*/
|
|
1092
|
+
realSocket[kPatched] = true;
|
|
1093
|
+
return realSocket.connect(connectionOptions);
|
|
1094
|
+
}
|
|
969
1095
|
};
|
|
970
1096
|
var TlsSocketController = class extends TcpSocketController {
|
|
971
1097
|
/**
|
|
@@ -1299,15 +1425,18 @@ var SocketInterceptor = class extends Interceptor {
|
|
|
1299
1425
|
}
|
|
1300
1426
|
process.nextTick(() => {
|
|
1301
1427
|
if (socket.destroyed) return;
|
|
1302
|
-
|
|
1428
|
+
/**
|
|
1429
|
+
* @note Expect a verdict on this connection from every
|
|
1430
|
+
* "connection" listener before emitting the event. With no
|
|
1431
|
+
* listeners to claim the connection (or once every listener
|
|
1432
|
+
* declines it), the controller passes it through as-is.
|
|
1433
|
+
*/
|
|
1434
|
+
controller.awaitVerdicts(interceptor.listenerCount("connection"));
|
|
1435
|
+
interceptor.emitter.emit(new SocketConnectionEvent({
|
|
1303
1436
|
socket: controller.serverSocket,
|
|
1304
1437
|
controller,
|
|
1305
1438
|
connectionOptions
|
|
1306
|
-
}))
|
|
1307
|
-
logger.verbose("no \"connection\" listeners found on the interceptor, passthrough...");
|
|
1308
|
-
controller.passthrough();
|
|
1309
|
-
return;
|
|
1310
|
-
}
|
|
1439
|
+
}));
|
|
1311
1440
|
logger.verbose("emitted \"connection\" event!");
|
|
1312
1441
|
});
|
|
1313
1442
|
logger.verbose("connecting the socket...");
|
|
@@ -1385,4 +1514,4 @@ var SocketInterceptor = class extends Interceptor {
|
|
|
1385
1514
|
//#endregion
|
|
1386
1515
|
export { getDeepPropertyDescriptor as a, unwrapPendingData as i, SocketController as n, patchesRegistry as o, kRawSocket as r, SocketInterceptor as t };
|
|
1387
1516
|
|
|
1388
|
-
//# sourceMappingURL=net-
|
|
1517
|
+
//# sourceMappingURL=net-Ca8p1rIe.js.map
|