@mswjs/interceptors 0.40.0 → 0.41.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/ClientRequest/package.json +7 -2
- package/RemoteHttpInterceptor/package.json +7 -2
- package/WebSocket/package.json +9 -2
- package/XMLHttpRequest/package.json +9 -3
- package/fetch/package.json +9 -3
- package/lib/browser/Interceptor-2mUoKZL1.d.mts +65 -0
- package/lib/browser/Interceptor-Deczogc8.d.cts +65 -0
- package/lib/browser/XMLHttpRequest-BUfglQD1.cjs +761 -0
- package/lib/browser/XMLHttpRequest-BUfglQD1.cjs.map +1 -0
- package/lib/browser/XMLHttpRequest-DS5fc8Qs.mjs +756 -0
- package/lib/browser/XMLHttpRequest-DS5fc8Qs.mjs.map +1 -0
- package/lib/browser/bufferUtils-BiiO6HZv.mjs +20 -0
- package/lib/browser/bufferUtils-BiiO6HZv.mjs.map +1 -0
- package/lib/browser/bufferUtils-Uc0eRItL.cjs +38 -0
- package/lib/browser/bufferUtils-Uc0eRItL.cjs.map +1 -0
- package/lib/browser/createRequestId-Cs4oXfa1.cjs +205 -0
- package/lib/browser/createRequestId-Cs4oXfa1.cjs.map +1 -0
- package/lib/browser/createRequestId-DQcIlohW.mjs +170 -0
- package/lib/browser/createRequestId-DQcIlohW.mjs.map +1 -0
- package/lib/browser/fetch-BHcqM3z7.cjs +253 -0
- package/lib/browser/fetch-BHcqM3z7.cjs.map +1 -0
- package/lib/browser/fetch-DSJoynSF.mjs +248 -0
- package/lib/browser/fetch-DSJoynSF.mjs.map +1 -0
- package/lib/browser/getRawRequest-BTaNLFr0.mjs +218 -0
- package/lib/browser/getRawRequest-BTaNLFr0.mjs.map +1 -0
- package/lib/browser/getRawRequest-zx8rUJL2.cjs +259 -0
- package/lib/browser/getRawRequest-zx8rUJL2.cjs.map +1 -0
- package/lib/browser/glossary-BdLS4k1H.d.cts +70 -0
- package/lib/browser/glossary-gEEJhK4S.d.mts +70 -0
- package/lib/browser/handleRequest-DI6a7Dty.cjs +189 -0
- package/lib/browser/handleRequest-DI6a7Dty.cjs.map +1 -0
- package/lib/browser/handleRequest-DxGbCTbb.mjs +178 -0
- package/lib/browser/handleRequest-DxGbCTbb.mjs.map +1 -0
- package/lib/browser/hasConfigurableGlobal-C8kXFDic.mjs +33 -0
- package/lib/browser/hasConfigurableGlobal-C8kXFDic.mjs.map +1 -0
- package/lib/browser/hasConfigurableGlobal-D7S3l5h6.cjs +45 -0
- package/lib/browser/hasConfigurableGlobal-D7S3l5h6.cjs.map +1 -0
- package/lib/browser/index.cjs +68 -0
- package/lib/browser/index.cjs.map +1 -0
- package/lib/browser/index.d.cts +87 -0
- package/lib/browser/index.d.mts +87 -0
- package/lib/browser/index.mjs +49 -77
- package/lib/browser/index.mjs.map +1 -1
- package/lib/browser/interceptors/WebSocket/index.cjs +641 -0
- package/lib/browser/interceptors/WebSocket/index.cjs.map +1 -0
- package/lib/browser/interceptors/WebSocket/index.d.cts +277 -0
- package/lib/browser/interceptors/WebSocket/index.d.mts +277 -0
- package/lib/browser/interceptors/WebSocket/index.mjs +607 -694
- package/lib/browser/interceptors/WebSocket/index.mjs.map +1 -1
- package/lib/browser/interceptors/XMLHttpRequest/index.cjs +7 -0
- package/lib/browser/interceptors/XMLHttpRequest/index.d.cts +15 -0
- package/lib/browser/interceptors/XMLHttpRequest/index.d.mts +15 -0
- package/lib/browser/interceptors/XMLHttpRequest/index.mjs +7 -12
- package/lib/browser/interceptors/fetch/index.cjs +6 -0
- package/lib/browser/interceptors/fetch/index.d.cts +13 -0
- package/lib/browser/interceptors/fetch/index.d.mts +13 -0
- package/lib/browser/interceptors/fetch/index.mjs +6 -11
- package/lib/browser/presets/browser.cjs +17 -0
- package/lib/browser/presets/browser.cjs.map +1 -0
- package/lib/browser/presets/browser.d.cts +12 -0
- package/lib/browser/presets/browser.d.mts +14 -0
- package/lib/browser/presets/browser.mjs +15 -19
- package/lib/browser/presets/browser.mjs.map +1 -1
- package/lib/node/BatchInterceptor-3LnAnLTx.cjs +49 -0
- package/lib/node/BatchInterceptor-3LnAnLTx.cjs.map +1 -0
- package/lib/node/BatchInterceptor-D7mXzHcQ.d.mts +26 -0
- package/lib/node/BatchInterceptor-DFaBPilf.mjs +44 -0
- package/lib/node/BatchInterceptor-DFaBPilf.mjs.map +1 -0
- package/lib/node/BatchInterceptor-D_YqR8qU.d.cts +26 -0
- package/lib/node/ClientRequest-2rDe54Ui.cjs +1043 -0
- package/lib/node/ClientRequest-2rDe54Ui.cjs.map +1 -0
- package/lib/node/ClientRequest-Ca8Qykuv.mjs +1034 -0
- package/lib/node/ClientRequest-Ca8Qykuv.mjs.map +1 -0
- package/lib/node/Interceptor-DEazpLJd.d.mts +133 -0
- package/lib/node/Interceptor-DJ2akVWI.d.cts +133 -0
- package/lib/node/RemoteHttpInterceptor.cjs +154 -0
- package/lib/node/RemoteHttpInterceptor.cjs.map +1 -0
- package/lib/node/RemoteHttpInterceptor.d.cts +39 -0
- package/lib/node/RemoteHttpInterceptor.d.mts +39 -0
- package/lib/node/RemoteHttpInterceptor.mjs +145 -190
- package/lib/node/RemoteHttpInterceptor.mjs.map +1 -1
- package/lib/node/XMLHttpRequest-B7kJdYYI.cjs +763 -0
- package/lib/node/XMLHttpRequest-B7kJdYYI.cjs.map +1 -0
- package/lib/node/XMLHttpRequest-C8dIZpds.mjs +757 -0
- package/lib/node/XMLHttpRequest-C8dIZpds.mjs.map +1 -0
- package/lib/node/bufferUtils-DiCTqG-7.cjs +38 -0
- package/lib/node/bufferUtils-DiCTqG-7.cjs.map +1 -0
- package/lib/node/bufferUtils-_8XfKIfX.mjs +20 -0
- package/lib/node/bufferUtils-_8XfKIfX.mjs.map +1 -0
- package/lib/node/chunk-CbDLau6x.cjs +34 -0
- package/lib/node/fetch-BmXpK10r.cjs +272 -0
- package/lib/node/fetch-BmXpK10r.cjs.map +1 -0
- package/lib/node/fetch-G1DVwDKG.mjs +265 -0
- package/lib/node/fetch-G1DVwDKG.mjs.map +1 -0
- package/lib/node/fetchUtils-BaY5iWXw.cjs +419 -0
- package/lib/node/fetchUtils-BaY5iWXw.cjs.map +1 -0
- package/lib/node/fetchUtils-CoU35g3M.mjs +359 -0
- package/lib/node/fetchUtils-CoU35g3M.mjs.map +1 -0
- package/lib/node/getRawRequest-BavnMWh_.cjs +36 -0
- package/lib/node/getRawRequest-BavnMWh_.cjs.map +1 -0
- package/lib/node/getRawRequest-DnwmXyOW.mjs +24 -0
- package/lib/node/getRawRequest-DnwmXyOW.mjs.map +1 -0
- package/lib/node/glossary-BLKRyLBd.cjs +12 -0
- package/lib/node/glossary-BLKRyLBd.cjs.map +1 -0
- package/lib/node/glossary-glQBRnVD.mjs +6 -0
- package/lib/node/glossary-glQBRnVD.mjs.map +1 -0
- package/lib/node/handleRequest-Bb7Y-XLw.cjs +220 -0
- package/lib/node/handleRequest-Bb7Y-XLw.cjs.map +1 -0
- package/lib/node/handleRequest-Y97UwBbF.mjs +190 -0
- package/lib/node/handleRequest-Y97UwBbF.mjs.map +1 -0
- package/lib/node/hasConfigurableGlobal-C97fWuaA.cjs +26 -0
- package/lib/node/hasConfigurableGlobal-C97fWuaA.cjs.map +1 -0
- package/lib/node/hasConfigurableGlobal-DBJA0vjm.mjs +20 -0
- package/lib/node/hasConfigurableGlobal-DBJA0vjm.mjs.map +1 -0
- package/lib/node/index-BMbJ8FXL.d.cts +113 -0
- package/lib/node/index-C0YAQ36w.d.mts +113 -0
- package/lib/node/index.cjs +30 -0
- package/lib/node/index.cjs.map +1 -0
- package/lib/node/index.d.cts +66 -0
- package/lib/node/index.d.mts +66 -0
- package/lib/node/index.mjs +13 -41
- package/lib/node/index.mjs.map +1 -1
- package/lib/node/interceptors/ClientRequest/index.cjs +6 -0
- package/lib/node/interceptors/ClientRequest/index.d.cts +2 -0
- package/lib/node/interceptors/ClientRequest/index.d.mts +3 -0
- package/lib/node/interceptors/ClientRequest/index.mjs +6 -11
- package/lib/node/interceptors/XMLHttpRequest/index.cjs +6 -0
- package/lib/node/interceptors/XMLHttpRequest/index.d.cts +14 -0
- package/lib/node/interceptors/XMLHttpRequest/index.d.mts +14 -0
- package/lib/node/interceptors/XMLHttpRequest/index.mjs +6 -13
- package/lib/node/interceptors/fetch/index.cjs +5 -0
- package/lib/node/interceptors/fetch/index.d.cts +12 -0
- package/lib/node/interceptors/fetch/index.d.mts +12 -0
- package/lib/node/interceptors/fetch/index.mjs +5 -12
- package/lib/node/node-DwCc6iuP.mjs +27 -0
- package/lib/node/node-DwCc6iuP.mjs.map +1 -0
- package/lib/node/node-dKdAf3tC.cjs +39 -0
- package/lib/node/node-dKdAf3tC.cjs.map +1 -0
- package/lib/node/presets/node.cjs +22 -0
- package/lib/node/presets/node.cjs.map +1 -0
- package/lib/node/presets/node.d.cts +13 -0
- package/lib/node/presets/node.d.mts +15 -0
- package/lib/node/presets/node.mjs +18 -23
- package/lib/node/presets/node.mjs.map +1 -1
- package/lib/node/utils/node/index.cjs +4 -0
- package/lib/node/utils/node/{index.d.ts → index.d.cts} +5 -2
- package/lib/node/utils/node/index.d.mts +16 -0
- package/lib/node/utils/node/index.mjs +3 -10
- package/package.json +33 -59
- package/presets/browser/package.json +2 -3
- package/presets/node/package.json +7 -2
- package/src/interceptors/ClientRequest/MockHttpSocket.ts +21 -8
- package/src/interceptors/ClientRequest/utils/parserUtils.ts +48 -0
- package/src/interceptors/WebSocket/WebSocketClientConnection.ts +3 -5
- package/src/interceptors/WebSocket/WebSocketOverride.ts +51 -5
- package/src/interceptors/WebSocket/WebSocketServerConnection.ts +3 -5
- package/src/interceptors/WebSocket/index.ts +4 -1
- package/src/interceptors/XMLHttpRequest/utils/getBodyByteLength.test.ts +2 -2
- package/lib/browser/Interceptor-af98b768.d.ts +0 -63
- package/lib/browser/chunk-2HUMWGRD.js +0 -37
- package/lib/browser/chunk-2HUMWGRD.js.map +0 -1
- package/lib/browser/chunk-2MCNQOY3.js +0 -851
- package/lib/browser/chunk-2MCNQOY3.js.map +0 -1
- package/lib/browser/chunk-57RIRQUY.js +0 -218
- package/lib/browser/chunk-57RIRQUY.js.map +0 -1
- package/lib/browser/chunk-6HYIRFX2.mjs +0 -22
- package/lib/browser/chunk-6HYIRFX2.mjs.map +0 -1
- package/lib/browser/chunk-FW45TRCB.js +0 -178
- package/lib/browser/chunk-FW45TRCB.js.map +0 -1
- package/lib/browser/chunk-JQ2S7G56.js +0 -185
- package/lib/browser/chunk-JQ2S7G56.js.map +0 -1
- package/lib/browser/chunk-LIKZF2VU.mjs +0 -218
- package/lib/browser/chunk-LIKZF2VU.mjs.map +0 -1
- package/lib/browser/chunk-LK6DILFK.js +0 -22
- package/lib/browser/chunk-LK6DILFK.js.map +0 -1
- package/lib/browser/chunk-MNT2FUCH.js +0 -301
- package/lib/browser/chunk-MNT2FUCH.js.map +0 -1
- package/lib/browser/chunk-VOUOVDAW.mjs +0 -178
- package/lib/browser/chunk-VOUOVDAW.mjs.map +0 -1
- package/lib/browser/chunk-VYSDLBSS.mjs +0 -37
- package/lib/browser/chunk-VYSDLBSS.mjs.map +0 -1
- package/lib/browser/chunk-WADP6VHN.mjs +0 -851
- package/lib/browser/chunk-WADP6VHN.mjs.map +0 -1
- package/lib/browser/chunk-WOWPV4GR.mjs +0 -301
- package/lib/browser/chunk-WOWPV4GR.mjs.map +0 -1
- package/lib/browser/chunk-Z5TSB3T6.mjs +0 -185
- package/lib/browser/chunk-Z5TSB3T6.mjs.map +0 -1
- package/lib/browser/glossary-f7ee1c9d.d.ts +0 -74
- package/lib/browser/index.d.ts +0 -82
- package/lib/browser/index.js +0 -83
- package/lib/browser/index.js.map +0 -1
- package/lib/browser/interceptors/WebSocket/index.d.ts +0 -271
- package/lib/browser/interceptors/WebSocket/index.js +0 -721
- package/lib/browser/interceptors/WebSocket/index.js.map +0 -1
- package/lib/browser/interceptors/XMLHttpRequest/index.d.ts +0 -14
- package/lib/browser/interceptors/XMLHttpRequest/index.js +0 -12
- package/lib/browser/interceptors/XMLHttpRequest/index.js.map +0 -1
- package/lib/browser/interceptors/XMLHttpRequest/index.mjs.map +0 -1
- package/lib/browser/interceptors/fetch/index.d.ts +0 -13
- package/lib/browser/interceptors/fetch/index.js +0 -11
- package/lib/browser/interceptors/fetch/index.js.map +0 -1
- package/lib/browser/interceptors/fetch/index.mjs.map +0 -1
- package/lib/browser/presets/browser.d.ts +0 -14
- package/lib/browser/presets/browser.js +0 -21
- package/lib/browser/presets/browser.js.map +0 -1
- package/lib/node/BatchInterceptor-cb9a2eee.d.ts +0 -24
- package/lib/node/Interceptor-dc0a39b5.d.ts +0 -136
- package/lib/node/RemoteHttpInterceptor.d.ts +0 -44
- package/lib/node/RemoteHttpInterceptor.js +0 -197
- package/lib/node/RemoteHttpInterceptor.js.map +0 -1
- package/lib/node/chunk-5UGIB6OX.mjs +0 -1126
- package/lib/node/chunk-5UGIB6OX.mjs.map +0 -1
- package/lib/node/chunk-5V3SIIW2.mjs +0 -853
- package/lib/node/chunk-5V3SIIW2.mjs.map +0 -1
- package/lib/node/chunk-6B3ZQOO2.js +0 -853
- package/lib/node/chunk-6B3ZQOO2.js.map +0 -1
- package/lib/node/chunk-6HYIRFX2.mjs +0 -22
- package/lib/node/chunk-6HYIRFX2.mjs.map +0 -1
- package/lib/node/chunk-6YM4PLBI.mjs +0 -7
- package/lib/node/chunk-6YM4PLBI.mjs.map +0 -1
- package/lib/node/chunk-73NOP3T5.js +0 -7
- package/lib/node/chunk-73NOP3T5.js.map +0 -1
- package/lib/node/chunk-7Q53NNPV.js +0 -189
- package/lib/node/chunk-7Q53NNPV.js.map +0 -1
- package/lib/node/chunk-DOWWQYXZ.js +0 -369
- package/lib/node/chunk-DOWWQYXZ.js.map +0 -1
- package/lib/node/chunk-FRZQJNBO.js +0 -318
- package/lib/node/chunk-FRZQJNBO.js.map +0 -1
- package/lib/node/chunk-GKN5RBVR.mjs +0 -32
- package/lib/node/chunk-GKN5RBVR.mjs.map +0 -1
- package/lib/node/chunk-J5MULIHT.js +0 -51
- package/lib/node/chunk-J5MULIHT.js.map +0 -1
- package/lib/node/chunk-JXGB54LE.mjs +0 -369
- package/lib/node/chunk-JXGB54LE.mjs.map +0 -1
- package/lib/node/chunk-LK6DILFK.js +0 -22
- package/lib/node/chunk-LK6DILFK.js.map +0 -1
- package/lib/node/chunk-OFW5L5ET.mjs +0 -318
- package/lib/node/chunk-OFW5L5ET.mjs.map +0 -1
- package/lib/node/chunk-PFGO5BSM.js +0 -25
- package/lib/node/chunk-PFGO5BSM.js.map +0 -1
- package/lib/node/chunk-R6T7CL5E.mjs +0 -189
- package/lib/node/chunk-R6T7CL5E.mjs.map +0 -1
- package/lib/node/chunk-SQ6RHTJR.mjs +0 -51
- package/lib/node/chunk-SQ6RHTJR.mjs.map +0 -1
- package/lib/node/chunk-SRMAQGPM.js +0 -30
- package/lib/node/chunk-SRMAQGPM.js.map +0 -1
- package/lib/node/chunk-T3TW4P64.js +0 -32
- package/lib/node/chunk-T3TW4P64.js.map +0 -1
- package/lib/node/chunk-TX5GBTFY.mjs +0 -25
- package/lib/node/chunk-TX5GBTFY.mjs.map +0 -1
- package/lib/node/chunk-VYO5XDY2.js +0 -1126
- package/lib/node/chunk-VYO5XDY2.js.map +0 -1
- package/lib/node/chunk-YWNGXXUQ.mjs +0 -30
- package/lib/node/chunk-YWNGXXUQ.mjs.map +0 -1
- package/lib/node/index.d.ts +0 -61
- package/lib/node/index.js +0 -45
- package/lib/node/index.js.map +0 -1
- package/lib/node/interceptors/ClientRequest/index.d.ts +0 -110
- package/lib/node/interceptors/ClientRequest/index.js +0 -11
- package/lib/node/interceptors/ClientRequest/index.js.map +0 -1
- package/lib/node/interceptors/ClientRequest/index.mjs.map +0 -1
- package/lib/node/interceptors/XMLHttpRequest/index.d.ts +0 -13
- package/lib/node/interceptors/XMLHttpRequest/index.js +0 -13
- package/lib/node/interceptors/XMLHttpRequest/index.js.map +0 -1
- package/lib/node/interceptors/XMLHttpRequest/index.mjs.map +0 -1
- package/lib/node/interceptors/fetch/index.d.ts +0 -12
- package/lib/node/interceptors/fetch/index.js +0 -12
- package/lib/node/interceptors/fetch/index.js.map +0 -1
- package/lib/node/interceptors/fetch/index.mjs.map +0 -1
- package/lib/node/presets/node.d.ts +0 -15
- package/lib/node/presets/node.js +0 -27
- package/lib/node/presets/node.js.map +0 -1
- package/lib/node/utils/node/index.js +0 -10
- package/lib/node/utils/node/index.js.map +0 -1
- package/lib/node/utils/node/index.mjs.map +0 -1
|
@@ -1,27 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
} from "../
|
|
4
|
-
import "../
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
} from "../
|
|
8
|
-
import "../chunk-6HYIRFX2.mjs";
|
|
9
|
-
import {
|
|
10
|
-
FetchInterceptor
|
|
11
|
-
} from "../chunk-OFW5L5ET.mjs";
|
|
12
|
-
import "../chunk-TX5GBTFY.mjs";
|
|
13
|
-
import "../chunk-6YM4PLBI.mjs";
|
|
14
|
-
import "../chunk-R6T7CL5E.mjs";
|
|
15
|
-
import "../chunk-JXGB54LE.mjs";
|
|
16
|
-
import "../chunk-YWNGXXUQ.mjs";
|
|
1
|
+
import "../fetchUtils-CoU35g3M.mjs";
|
|
2
|
+
import "../bufferUtils-_8XfKIfX.mjs";
|
|
3
|
+
import { t as ClientRequestInterceptor } from "../ClientRequest-Ca8Qykuv.mjs";
|
|
4
|
+
import "../handleRequest-Y97UwBbF.mjs";
|
|
5
|
+
import "../node-DwCc6iuP.mjs";
|
|
6
|
+
import { t as XMLHttpRequestInterceptor } from "../XMLHttpRequest-C8dIZpds.mjs";
|
|
7
|
+
import { t as FetchInterceptor } from "../fetch-G1DVwDKG.mjs";
|
|
17
8
|
|
|
18
|
-
|
|
9
|
+
//#region src/presets/node.ts
|
|
10
|
+
/**
|
|
11
|
+
* The default preset provisions the interception of requests
|
|
12
|
+
* regardless of their type (http/https/XMLHttpRequest).
|
|
13
|
+
*/
|
|
19
14
|
var node_default = [
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
new ClientRequestInterceptor(),
|
|
16
|
+
new XMLHttpRequestInterceptor(),
|
|
17
|
+
new FetchInterceptor()
|
|
23
18
|
];
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { node_default as default };
|
|
27
22
|
//# sourceMappingURL=node.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/presets/node.ts"],"sourcesContent":["import { ClientRequestInterceptor } from '../interceptors/ClientRequest'\nimport { XMLHttpRequestInterceptor } from '../interceptors/XMLHttpRequest'\nimport { FetchInterceptor } from '../interceptors/fetch'\n\n/**\n * The default preset provisions the interception of requests\n * regardless of their type (http/https/XMLHttpRequest).\n */\nexport default [\n new ClientRequestInterceptor(),\n new XMLHttpRequestInterceptor(),\n new FetchInterceptor(),\n] as const\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"node.mjs","names":[],"sources":["../../../src/presets/node.ts"],"sourcesContent":["import { ClientRequestInterceptor } from '../interceptors/ClientRequest'\nimport { XMLHttpRequestInterceptor } from '../interceptors/XMLHttpRequest'\nimport { FetchInterceptor } from '../interceptors/fetch'\n\n/**\n * The default preset provisions the interception of requests\n * regardless of their type (http/https/XMLHttpRequest).\n */\nexport default [\n new ClientRequestInterceptor(),\n new XMLHttpRequestInterceptor(),\n new FetchInterceptor(),\n] as const\n"],"mappings":";;;;;;;;;;;;;AAQA,mBAAe;CACb,IAAI,0BAA0B;CAC9B,IAAI,2BAA2B;CAC/B,IAAI,kBAAkB;CACvB"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { Readable } from
|
|
1
|
+
import { Readable } from "node:stream";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/node/index.d.ts
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Returns the request body stream of the given request.
|
|
@@ -9,5 +11,6 @@ import { Readable } from 'node:stream';
|
|
|
9
11
|
*/
|
|
10
12
|
declare function getClientRequestBodyStream(request: Request): Readable;
|
|
11
13
|
declare function setRawRequestBodyStream(request: Request, stream: Readable): void;
|
|
12
|
-
|
|
14
|
+
//#endregion
|
|
13
15
|
export { getClientRequestBodyStream, setRawRequestBodyStream };
|
|
16
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Readable } from "node:stream";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/node/index.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns the request body stream of the given request.
|
|
7
|
+
* @note This is only relevant in the context of `http.ClientRequest`.
|
|
8
|
+
* This function will throw if the given `request` wasn't created based on
|
|
9
|
+
* the `http.ClientRequest` instance.
|
|
10
|
+
* You must rely on the web stream consumers for other request clients.
|
|
11
|
+
*/
|
|
12
|
+
declare function getClientRequestBodyStream(request: Request): Readable;
|
|
13
|
+
declare function setRawRequestBodyStream(request: Request, stream: Readable): void;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { getClientRequestBodyStream, setRawRequestBodyStream };
|
|
16
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "../../chunk-GKN5RBVR.mjs";
|
|
5
|
-
import "../../chunk-YWNGXXUQ.mjs";
|
|
6
|
-
export {
|
|
7
|
-
getClientRequestBodyStream,
|
|
8
|
-
setRawRequestBodyStream
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
import { n as setRawRequestBodyStream, t as getClientRequestBodyStream } from "../../node-DwCc6iuP.mjs";
|
|
2
|
+
|
|
3
|
+
export { getClientRequestBodyStream, setRawRequestBodyStream };
|
package/package.json
CHANGED
|
@@ -1,104 +1,80 @@
|
|
|
1
1
|
{
|
|
2
|
+
"type": "commonjs",
|
|
2
3
|
"name": "@mswjs/interceptors",
|
|
3
4
|
"description": "Low-level HTTP/HTTPS/XHR/fetch request interception library.",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"main": "./lib/node/index.
|
|
5
|
+
"version": "0.41.1",
|
|
6
|
+
"main": "./lib/node/index.cjs",
|
|
6
7
|
"module": "./lib/node/index.mjs",
|
|
7
|
-
"types": "./lib/node/index.d.
|
|
8
|
+
"types": "./lib/node/index.d.cts",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
|
-
"types": "./lib/node/index.d.ts",
|
|
11
11
|
"browser": {
|
|
12
|
-
"types": "./lib/browser/index.d.ts",
|
|
13
|
-
"require": "./lib/browser/index.js",
|
|
14
12
|
"import": "./lib/browser/index.mjs",
|
|
15
|
-
"default": "./lib/browser/index.
|
|
13
|
+
"default": "./lib/browser/index.cjs"
|
|
16
14
|
},
|
|
17
|
-
"require": "./lib/node/index.js",
|
|
18
15
|
"import": "./lib/node/index.mjs",
|
|
19
|
-
"default": "./lib/node/index.
|
|
16
|
+
"default": "./lib/node/index.cjs"
|
|
20
17
|
},
|
|
21
18
|
"./ClientRequest": {
|
|
22
|
-
"types": "./lib/node/interceptors/ClientRequest/index.d.ts",
|
|
23
19
|
"node": {
|
|
24
|
-
"require": "./lib/node/interceptors/ClientRequest/index.
|
|
20
|
+
"require": "./lib/node/interceptors/ClientRequest/index.cjs",
|
|
25
21
|
"import": "./lib/node/interceptors/ClientRequest/index.mjs"
|
|
26
22
|
},
|
|
27
23
|
"browser": null,
|
|
28
|
-
"require": "./lib/node/interceptors/ClientRequest/index.
|
|
24
|
+
"require": "./lib/node/interceptors/ClientRequest/index.cjs",
|
|
29
25
|
"import": "./lib/node/interceptors/ClientRequest/index.mjs",
|
|
30
|
-
"default": "./lib/node/interceptors/ClientRequest/index.
|
|
26
|
+
"default": "./lib/node/interceptors/ClientRequest/index.cjs"
|
|
31
27
|
},
|
|
32
28
|
"./XMLHttpRequest": {
|
|
33
|
-
"browser":
|
|
34
|
-
|
|
35
|
-
"require": "./lib/browser/interceptors/XMLHttpRequest/index.js",
|
|
36
|
-
"import": "./lib/browser/interceptors/XMLHttpRequest/index.mjs",
|
|
37
|
-
"default": "./lib/browser/interceptors/XMLHttpRequest/index.js"
|
|
38
|
-
},
|
|
39
|
-
"types": "./lib/node/interceptors/XMLHttpRequest/index.d.ts",
|
|
40
|
-
"require": "./lib/node/interceptors/XMLHttpRequest/index.js",
|
|
29
|
+
"browser": "./lib/browser/interceptors/XMLHttpRequest/index.mjs",
|
|
30
|
+
"require": "./lib/node/interceptors/XMLHttpRequest/index.cjs",
|
|
41
31
|
"import": "./lib/node/interceptors/XMLHttpRequest/index.mjs",
|
|
42
|
-
"default": "./lib/node/interceptors/XMLHttpRequest/index.
|
|
32
|
+
"default": "./lib/node/interceptors/XMLHttpRequest/index.cjs"
|
|
43
33
|
},
|
|
44
34
|
"./fetch": {
|
|
45
|
-
"browser":
|
|
46
|
-
|
|
47
|
-
"require": "./lib/browser/interceptors/fetch/index.js",
|
|
48
|
-
"import": "./lib/browser/interceptors/fetch/index.mjs",
|
|
49
|
-
"default": "./lib/browser/interceptors/fetch/index.js"
|
|
50
|
-
},
|
|
51
|
-
"types": "./lib/node/interceptors/fetch/index.d.ts",
|
|
52
|
-
"require": "./lib/node/interceptors/fetch/index.js",
|
|
35
|
+
"browser": "./lib/browser/interceptors/fetch/index.mjs",
|
|
36
|
+
"require": "./lib/node/interceptors/fetch/index.cjs",
|
|
53
37
|
"import": "./lib/node/interceptors/fetch/index.mjs",
|
|
54
|
-
"default": "./lib/node/interceptors/fetch/index.
|
|
38
|
+
"default": "./lib/node/interceptors/fetch/index.cjs"
|
|
55
39
|
},
|
|
56
40
|
"./WebSocket": {
|
|
57
|
-
"
|
|
58
|
-
"require": "./lib/browser/interceptors/WebSocket/index.js",
|
|
41
|
+
"require": "./lib/browser/interceptors/WebSocket/index.cjs",
|
|
59
42
|
"import": "./lib/browser/interceptors/WebSocket/index.mjs",
|
|
60
|
-
"default": "./lib/browser/interceptors/WebSocket/index.
|
|
43
|
+
"default": "./lib/browser/interceptors/WebSocket/index.cjs"
|
|
61
44
|
},
|
|
62
45
|
"./RemoteHttpInterceptor": {
|
|
63
|
-
"types": "./lib/node/RemoteHttpInterceptor.d.ts",
|
|
64
46
|
"node": {
|
|
65
|
-
"require": "./lib/node/RemoteHttpInterceptor.
|
|
47
|
+
"require": "./lib/node/RemoteHttpInterceptor.cjs",
|
|
66
48
|
"import": "./lib/node/RemoteHttpInterceptor.mjs"
|
|
67
49
|
},
|
|
68
50
|
"browser": null,
|
|
69
|
-
"require": "./lib/node/RemoteHttpInterceptor.
|
|
51
|
+
"require": "./lib/node/RemoteHttpInterceptor.cjs",
|
|
70
52
|
"import": "./lib/node/RemoteHttpInterceptor.mjs",
|
|
71
|
-
"default": "./lib/node/RemoteHttpInterceptor.
|
|
53
|
+
"default": "./lib/node/RemoteHttpInterceptor.cjs"
|
|
72
54
|
},
|
|
73
55
|
"./presets/node": {
|
|
74
|
-
"types": "./lib/node/presets/node.d.ts",
|
|
75
56
|
"node": {
|
|
76
|
-
"require": "./lib/node/presets/node.
|
|
57
|
+
"require": "./lib/node/presets/node.cjs",
|
|
77
58
|
"import": "./lib/node/presets/node.mjs"
|
|
78
59
|
},
|
|
79
60
|
"browser": null,
|
|
80
|
-
"require": "./lib/node/presets/node.
|
|
61
|
+
"require": "./lib/node/presets/node.cjs",
|
|
81
62
|
"import": "./lib/node/presets/node.mjs",
|
|
82
|
-
"default": "./lib/node/presets/node.
|
|
63
|
+
"default": "./lib/node/presets/node.cjs"
|
|
83
64
|
},
|
|
84
65
|
"./presets/browser": {
|
|
85
|
-
"browser":
|
|
86
|
-
|
|
87
|
-
"require": "./lib/browser/presets/browser.js",
|
|
88
|
-
"import": "./lib/browser/presets/browser.mjs",
|
|
89
|
-
"default": "./lib/browser/presets/browser.js"
|
|
90
|
-
}
|
|
66
|
+
"browser": "./lib/browser/presets/browser.mjs",
|
|
67
|
+
"node": null
|
|
91
68
|
},
|
|
92
69
|
"./utils/node": {
|
|
93
|
-
"types": "./lib/node/utils/node/index.d.ts",
|
|
94
70
|
"node": {
|
|
95
|
-
"require": "./lib/node/utils/node/index.
|
|
71
|
+
"require": "./lib/node/utils/node/index.cjs",
|
|
96
72
|
"import": "./lib/node/utils/node/index.mjs"
|
|
97
73
|
},
|
|
98
74
|
"browser": null,
|
|
99
|
-
"require": "./lib/node/utils/node/index.
|
|
75
|
+
"require": "./lib/node/utils/node/index.cjs",
|
|
100
76
|
"import": "./lib/node/utils/node/index.mjs",
|
|
101
|
-
"default": "./lib/node/utils/node/index.
|
|
77
|
+
"default": "./lib/node/utils/node/index.cjs"
|
|
102
78
|
}
|
|
103
79
|
},
|
|
104
80
|
"author": "Artem Zakharchenko",
|
|
@@ -118,14 +94,13 @@
|
|
|
118
94
|
"presets"
|
|
119
95
|
],
|
|
120
96
|
"repository": {
|
|
121
|
-
"type": "git",
|
|
122
97
|
"url": "https://github.com/mswjs/interceptors"
|
|
123
98
|
},
|
|
124
99
|
"devDependencies": {
|
|
125
100
|
"@commitlint/cli": "^19.7.1",
|
|
126
101
|
"@commitlint/config-conventional": "^19.7.1",
|
|
127
102
|
"@open-draft/test-server": "^0.5.1",
|
|
128
|
-
"@ossjs/release": "^0.
|
|
103
|
+
"@ossjs/release": "^0.10.1",
|
|
129
104
|
"@playwright/test": "^1.51.0",
|
|
130
105
|
"@types/cors": "^2.8.12",
|
|
131
106
|
"@types/express": "^5.0.0",
|
|
@@ -151,20 +126,20 @@
|
|
|
151
126
|
"happy-dom": "^17.3.0",
|
|
152
127
|
"jsdom": "^26.1.0",
|
|
153
128
|
"node-fetch": "3.3.2",
|
|
154
|
-
"rimraf": "^6.0.1",
|
|
155
129
|
"simple-git-hooks": "^2.7.0",
|
|
156
130
|
"socket.io": "^4.7.4",
|
|
157
131
|
"socket.io-client": "^4.7.4",
|
|
158
132
|
"socket.io-parser": "^4.2.4",
|
|
159
133
|
"superagent": "^10.1.1",
|
|
160
134
|
"supertest": "^7.0.0",
|
|
161
|
-
"
|
|
135
|
+
"tsdown": "^0.18.1",
|
|
162
136
|
"typescript": "^5.8.2",
|
|
163
137
|
"undici": "^7.4.0",
|
|
164
138
|
"vitest": "^3.0.8",
|
|
165
139
|
"vitest-environment-miniflare": "^2.14.1",
|
|
166
140
|
"wait-for-expect": "^3.0.2",
|
|
167
141
|
"web-encoding": "^1.1.5",
|
|
142
|
+
"webpack": "^5.105.0",
|
|
168
143
|
"webpack-http-server": "^0.5.0",
|
|
169
144
|
"ws": "^8.18.1"
|
|
170
145
|
},
|
|
@@ -198,15 +173,14 @@
|
|
|
198
173
|
}
|
|
199
174
|
},
|
|
200
175
|
"scripts": {
|
|
201
|
-
"start": "
|
|
176
|
+
"start": "tsdown --watch",
|
|
202
177
|
"test": "pnpm test:unit && pnpm test:integration",
|
|
203
178
|
"test:unit": "vitest",
|
|
204
179
|
"test:integration": "pnpm test:node && pnpm test:browser",
|
|
205
180
|
"test:node": "vitest -c test/vitest.config.js",
|
|
206
181
|
"test:browser": "pnpm playwright test -c test/playwright.config.ts",
|
|
207
182
|
"test:nock": "./test/third-party/nock.sh",
|
|
208
|
-
"
|
|
209
|
-
"build": "pnpm clean && cross-env NODE_ENV=production tsup --splitting",
|
|
183
|
+
"build": "tsdown",
|
|
210
184
|
"release": "release publish"
|
|
211
185
|
}
|
|
212
186
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"main": "../../lib/browser/presets/browser.
|
|
2
|
+
"main": "../../lib/browser/presets/browser.mjs",
|
|
3
3
|
"module": "../../lib/browser/presets/browser.mjs",
|
|
4
|
-
"browser": "../../lib/browser/presets/browser.
|
|
5
|
-
"types": "../../lib/browser/presets/browser.d.ts"
|
|
4
|
+
"browser": "../../lib/browser/presets/browser.mjs"
|
|
6
5
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"main": "../../lib/node/presets/node.
|
|
2
|
+
"main": "../../lib/node/presets/node.cjs",
|
|
3
3
|
"module": "../../lib/node/presets/node.mjs",
|
|
4
4
|
"browser": null,
|
|
5
|
-
"
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"import": "./../lib/node/presets/node.mjs",
|
|
8
|
+
"default": "./../lib/node/presets/node.cjs"
|
|
9
|
+
}
|
|
10
|
+
}
|
|
6
11
|
}
|
|
@@ -13,12 +13,12 @@ import { MockSocket } from '../Socket/MockSocket'
|
|
|
13
13
|
import type { NormalizedSocketWriteArgs } from '../Socket/utils/normalizeSocketWriteArgs'
|
|
14
14
|
import { isPropertyAccessible } from '../../utils/isPropertyAccessible'
|
|
15
15
|
import { baseUrlFromConnectionOptions } from '../Socket/utils/baseUrlFromConnectionOptions'
|
|
16
|
-
import { createServerErrorResponse } from '../../utils/responseUtils'
|
|
17
16
|
import { createRequestId } from '../../createRequestId'
|
|
18
17
|
import { getRawFetchHeaders } from './utils/recordRawHeaders'
|
|
19
18
|
import { FetchResponse } from '../../utils/fetchUtils'
|
|
20
19
|
import { setRawRequest } from '../../getRawRequest'
|
|
21
20
|
import { setRawRequestBodyStream } from '../../utils/node'
|
|
21
|
+
import { freeParser } from './utils/parserUtils'
|
|
22
22
|
|
|
23
23
|
type HttpConnectionOptions = any
|
|
24
24
|
|
|
@@ -136,7 +136,7 @@ export class MockHttpSocket extends MockSocket {
|
|
|
136
136
|
|
|
137
137
|
// Once the socket is finished, nothing can write to it
|
|
138
138
|
// anymore. It has also flushed any buffered chunks.
|
|
139
|
-
this.once('finish', () => this.requestParser
|
|
139
|
+
this.once('finish', () => freeParser(this.requestParser, this))
|
|
140
140
|
|
|
141
141
|
if (this.baseUrl.protocol === 'https:') {
|
|
142
142
|
Reflect.set(this, 'encrypted', true)
|
|
@@ -146,7 +146,11 @@ export class MockHttpSocket extends MockSocket {
|
|
|
146
146
|
Reflect.set(this, 'getProtocol', () => 'TLSv1.3')
|
|
147
147
|
Reflect.set(this, 'getSession', () => undefined)
|
|
148
148
|
Reflect.set(this, 'isSessionReused', () => false)
|
|
149
|
-
Reflect.set(this, 'getCipher', () => ({
|
|
149
|
+
Reflect.set(this, 'getCipher', () => ({
|
|
150
|
+
name: 'AES256-SHA',
|
|
151
|
+
standardName: 'TLS_RSA_WITH_AES_256_CBC_SHA',
|
|
152
|
+
version: 'TLSv1.3',
|
|
153
|
+
}))
|
|
150
154
|
}
|
|
151
155
|
}
|
|
152
156
|
|
|
@@ -165,7 +169,7 @@ export class MockHttpSocket extends MockSocket {
|
|
|
165
169
|
// Destroy the response parser when the socket gets destroyed.
|
|
166
170
|
// Normally, we should listen to the "close" event but it
|
|
167
171
|
// can be suppressed by using the "emitClose: false" option.
|
|
168
|
-
this.responseParser
|
|
172
|
+
freeParser(this.responseParser, this)
|
|
169
173
|
|
|
170
174
|
if (error) {
|
|
171
175
|
this.emit('error', error)
|
|
@@ -202,9 +206,18 @@ export class MockHttpSocket extends MockSocket {
|
|
|
202
206
|
})
|
|
203
207
|
}
|
|
204
208
|
|
|
205
|
-
//
|
|
206
|
-
|
|
207
|
-
|
|
209
|
+
// The client-facing socket can be destroyed in two ways:
|
|
210
|
+
// 1. The developer destroys the socket.
|
|
211
|
+
// 2. The passthrough socket "close" is forwarded to the socket.
|
|
212
|
+
this.once('close', () => {
|
|
213
|
+
socket.removeAllListeners()
|
|
214
|
+
|
|
215
|
+
// If the closure didn't originate from the passthrough socket, destroy it.
|
|
216
|
+
if (!socket.destroyed) {
|
|
217
|
+
socket.destroy()
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
this.originalSocket = undefined
|
|
208
221
|
})
|
|
209
222
|
|
|
210
223
|
this.address = socket.address.bind(socket)
|
|
@@ -259,7 +272,7 @@ export class MockHttpSocket extends MockSocket {
|
|
|
259
272
|
'getProtocol',
|
|
260
273
|
'getSession',
|
|
261
274
|
'isSessionReused',
|
|
262
|
-
'getCipher'
|
|
275
|
+
'getCipher',
|
|
263
276
|
]
|
|
264
277
|
|
|
265
278
|
tlsProperties.forEach((propertyName) => {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Socket } from 'node:net'
|
|
2
|
+
import { HTTPParser } from '_http_common'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @see https://github.com/nodejs/node/blob/f3adc11e37b8bfaaa026ea85c1cf22e3a0e29ae9/lib/_http_common.js#L180
|
|
6
|
+
*/
|
|
7
|
+
export function freeParser(parser: HTTPParser<any>, socket?: Socket): void {
|
|
8
|
+
if (parser._consumed) {
|
|
9
|
+
parser.unconsume()
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
parser._headers = []
|
|
13
|
+
parser._url = ''
|
|
14
|
+
parser.socket = null
|
|
15
|
+
parser.incoming = null
|
|
16
|
+
parser.outgoing = null
|
|
17
|
+
parser.maxHeaderPairs = 2000
|
|
18
|
+
parser._consumed = false
|
|
19
|
+
parser.onIncoming = null
|
|
20
|
+
|
|
21
|
+
parser[HTTPParser.kOnHeaders] = null
|
|
22
|
+
parser[HTTPParser.kOnHeadersComplete] = null
|
|
23
|
+
parser[HTTPParser.kOnMessageBegin] = null
|
|
24
|
+
parser[HTTPParser.kOnMessageComplete] = null
|
|
25
|
+
parser[HTTPParser.kOnBody] = null
|
|
26
|
+
parser[HTTPParser.kOnExecute] = null
|
|
27
|
+
parser[HTTPParser.kOnTimeout] = null
|
|
28
|
+
|
|
29
|
+
parser.remove()
|
|
30
|
+
parser.free()
|
|
31
|
+
|
|
32
|
+
if (socket) {
|
|
33
|
+
/**
|
|
34
|
+
* @note Unassigning the socket's parser will fail this assertion
|
|
35
|
+
* if there's still some data being processed on the socket:
|
|
36
|
+
* @see https://github.com/nodejs/node/blob/4e1f39b678b37017ac9baa0971e3aeecd3b67b51/lib/_http_client.js#L613
|
|
37
|
+
*/
|
|
38
|
+
if (socket.destroyed) {
|
|
39
|
+
// @ts-expect-error Node.js internals.
|
|
40
|
+
socket.parser = null
|
|
41
|
+
} else {
|
|
42
|
+
socket.once('end', () => {
|
|
43
|
+
// @ts-expect-error Node.js internals.
|
|
44
|
+
socket.parser = null
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -19,7 +19,7 @@ export abstract class WebSocketClientConnectionProtocol {
|
|
|
19
19
|
public abstract close(code?: number, reason?: string): void
|
|
20
20
|
|
|
21
21
|
public abstract addEventListener<
|
|
22
|
-
EventType extends keyof WebSocketClientEventMap
|
|
22
|
+
EventType extends keyof WebSocketClientEventMap,
|
|
23
23
|
>(
|
|
24
24
|
type: EventType,
|
|
25
25
|
listener: WebSocketEventListener<WebSocketClientEventMap[EventType]>,
|
|
@@ -27,7 +27,7 @@ export abstract class WebSocketClientConnectionProtocol {
|
|
|
27
27
|
): void
|
|
28
28
|
|
|
29
29
|
public abstract removeEventListener<
|
|
30
|
-
EventType extends keyof WebSocketClientEventMap
|
|
30
|
+
EventType extends keyof WebSocketClientEventMap,
|
|
31
31
|
>(
|
|
32
32
|
event: EventType,
|
|
33
33
|
listener: WebSocketEventListener<WebSocketClientEventMap[EventType]>,
|
|
@@ -40,9 +40,7 @@ export abstract class WebSocketClientConnectionProtocol {
|
|
|
40
40
|
* client connection. The user can control the connection,
|
|
41
41
|
* send and receive events.
|
|
42
42
|
*/
|
|
43
|
-
export class WebSocketClientConnection
|
|
44
|
-
implements WebSocketClientConnectionProtocol
|
|
45
|
-
{
|
|
43
|
+
export class WebSocketClientConnection implements WebSocketClientConnectionProtocol {
|
|
46
44
|
public readonly id: string
|
|
47
45
|
public readonly url: URL
|
|
48
46
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { invariant } from 'outvariant'
|
|
2
|
+
import { DeferredPromise } from '@open-draft/deferred-promise'
|
|
2
3
|
import type { WebSocketData } from './WebSocketTransport'
|
|
3
4
|
import { bindEvent } from './utils/bindEvent'
|
|
4
5
|
import { CloseEvent } from './utils/events'
|
|
5
|
-
import { DeferredPromise } from '@open-draft/deferred-promise'
|
|
6
6
|
|
|
7
7
|
export type WebSocketEventListener<
|
|
8
|
-
EventType extends WebSocketEventMap[keyof WebSocketEventMap] = Event
|
|
8
|
+
EventType extends WebSocketEventMap[keyof WebSocketEventMap] = Event,
|
|
9
9
|
> = (this: WebSocket, event: EventType) => void
|
|
10
10
|
|
|
11
11
|
const WEBSOCKET_CLOSE_CODE_RANGE_ERROR =
|
|
@@ -44,7 +44,7 @@ export class WebSocketOverride extends EventTarget implements WebSocket {
|
|
|
44
44
|
|
|
45
45
|
constructor(url: string | URL, protocols?: string | Array<string>) {
|
|
46
46
|
super()
|
|
47
|
-
this.url = url
|
|
47
|
+
this.url = resolveWebSocketUrl(url)
|
|
48
48
|
this.protocol = ''
|
|
49
49
|
this.extensions = ''
|
|
50
50
|
this.binaryType = 'blob'
|
|
@@ -62,8 +62,8 @@ export class WebSocketOverride extends EventTarget implements WebSocket {
|
|
|
62
62
|
typeof protocols === 'string'
|
|
63
63
|
? protocols
|
|
64
64
|
: Array.isArray(protocols) && protocols.length > 0
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
? protocols[0]
|
|
66
|
+
: ''
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
69
|
* @note Check that nothing has prevented this connection
|
|
@@ -249,3 +249,49 @@ function getDataSize(data: WebSocketData): number {
|
|
|
249
249
|
|
|
250
250
|
return data.byteLength
|
|
251
251
|
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Resolve potentially relative WebSocket URLs the same way
|
|
255
|
+
* the browser does (replace the protocol, use the origin, etc).
|
|
256
|
+
*
|
|
257
|
+
* @see https://websockets.spec.whatwg.org//#dom-websocket-websocket
|
|
258
|
+
*/
|
|
259
|
+
function resolveWebSocketUrl(url: string | URL): string {
|
|
260
|
+
if (typeof url === 'string') {
|
|
261
|
+
/**
|
|
262
|
+
* @note Cast the string to a URL first so the parsing errors
|
|
263
|
+
* are thrown as a part of the WebSocket constructor, not consumers.
|
|
264
|
+
*/
|
|
265
|
+
const urlRecord = new URL(
|
|
266
|
+
url,
|
|
267
|
+
typeof location !== 'undefined' ? location.href : undefined
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
return resolveWebSocketUrl(urlRecord)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (url.protocol === 'http:') {
|
|
274
|
+
url.protocol = 'ws:'
|
|
275
|
+
} else if (url.protocol === 'https:') {
|
|
276
|
+
url.protocol = 'wss:'
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (url.protocol !== 'ws:' && url.protocol !== 'wss:') {
|
|
280
|
+
/**
|
|
281
|
+
* @note These errors are modeled after the browser errors.
|
|
282
|
+
* The exact error messages aren't provided in the specification.
|
|
283
|
+
* Node.js uses more obscure error messages that I don't wish to replicate.
|
|
284
|
+
*/
|
|
285
|
+
throw new SyntaxError(
|
|
286
|
+
`Failed to construct 'WebSocket': The URL's scheme must be either 'http', 'https', 'ws', or 'wss'. '${url.protocol}' is not allowed.`
|
|
287
|
+
)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (url.hash !== '') {
|
|
291
|
+
throw new SyntaxError(
|
|
292
|
+
`Failed to construct 'WebSocket': The URL contains a fragment identifier ('${url.hash}'). Fragment identifiers are not allowed in WebSocket URLs.`
|
|
293
|
+
)
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return url.href
|
|
297
|
+
}
|
|
@@ -30,7 +30,7 @@ export abstract class WebSocketServerConnectionProtocol {
|
|
|
30
30
|
public abstract close(): void
|
|
31
31
|
|
|
32
32
|
public abstract addEventListener<
|
|
33
|
-
EventType extends keyof WebSocketServerEventMap
|
|
33
|
+
EventType extends keyof WebSocketServerEventMap,
|
|
34
34
|
>(
|
|
35
35
|
event: EventType,
|
|
36
36
|
listener: WebSocketEventListener<WebSocketServerEventMap[EventType]>,
|
|
@@ -38,7 +38,7 @@ export abstract class WebSocketServerConnectionProtocol {
|
|
|
38
38
|
): void
|
|
39
39
|
|
|
40
40
|
public abstract removeEventListener<
|
|
41
|
-
EventType extends keyof WebSocketServerEventMap
|
|
41
|
+
EventType extends keyof WebSocketServerEventMap,
|
|
42
42
|
>(
|
|
43
43
|
event: EventType,
|
|
44
44
|
listener: WebSocketEventListener<WebSocketServerEventMap[EventType]>,
|
|
@@ -51,9 +51,7 @@ export abstract class WebSocketServerConnectionProtocol {
|
|
|
51
51
|
* WebSocket server connection. It's idle by default but you can
|
|
52
52
|
* establish it by calling `server.connect()`.
|
|
53
53
|
*/
|
|
54
|
-
export class WebSocketServerConnection
|
|
55
|
-
implements WebSocketServerConnectionProtocol
|
|
56
|
-
{
|
|
54
|
+
export class WebSocketServerConnection implements WebSocketServerConnectionProtocol {
|
|
57
55
|
/**
|
|
58
56
|
* A WebSocket instance connected to the original server.
|
|
59
57
|
*/
|
|
@@ -19,7 +19,10 @@ import { bindEvent } from './utils/bindEvent'
|
|
|
19
19
|
import { hasConfigurableGlobal } from '../../utils/hasConfigurableGlobal'
|
|
20
20
|
import { emitAsync } from '../../utils/emitAsync'
|
|
21
21
|
|
|
22
|
-
export {
|
|
22
|
+
export {
|
|
23
|
+
type WebSocketData,
|
|
24
|
+
type WebSocketTransport,
|
|
25
|
+
} from './WebSocketTransport'
|
|
23
26
|
export {
|
|
24
27
|
WebSocketClientEventMap,
|
|
25
28
|
WebSocketClientConnectionProtocol,
|
|
@@ -88,7 +88,7 @@ it('calculates body length from the FormData request body', async () => {
|
|
|
88
88
|
body: formData,
|
|
89
89
|
})
|
|
90
90
|
)
|
|
91
|
-
).resolves.toBe(
|
|
91
|
+
).resolves.toBe(129)
|
|
92
92
|
})
|
|
93
93
|
|
|
94
94
|
it('calculates body length from the ReadableStream request body', async () => {
|
|
@@ -149,7 +149,7 @@ it('calculates body length from the FormData response body', async () => {
|
|
|
149
149
|
const formData = new FormData()
|
|
150
150
|
formData.append('hello', 'world')
|
|
151
151
|
|
|
152
|
-
await expect(getBodyByteLength(new Response(formData))).resolves.toBe(
|
|
152
|
+
await expect(getBodyByteLength(new Response(formData))).resolves.toBe(129)
|
|
153
153
|
})
|
|
154
154
|
|
|
155
155
|
it('calculates body length from the ReadableStream response body', async () => {
|