@mswjs/interceptors 0.41.8 → 0.42.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 +274 -228
- package/lib/browser/{bufferUtils-BiiO6HZv.mjs → buffer-utils-DJj7YzLG.js} +3 -3
- package/lib/browser/buffer-utils-DJj7YzLG.js.map +1 -0
- package/lib/browser/create-request-id-DlEd4GOA.js +184 -0
- package/lib/browser/create-request-id-DlEd4GOA.js.map +1 -0
- package/lib/browser/{getRawRequest-B1BqgWG6.mjs → fetch-utils-zxA_SD66.js} +123 -52
- package/lib/browser/fetch-utils-zxA_SD66.js.map +1 -0
- package/lib/browser/handle-request-CIOa9O-N.js +167 -0
- package/lib/browser/handle-request-CIOa9O-N.js.map +1 -0
- package/lib/{node/hasConfigurableGlobal-BiTmog1u.mjs → browser/has-configurable-global-Cew-dYqk.js} +5 -7
- package/lib/browser/has-configurable-global-Cew-dYqk.js.map +1 -0
- package/lib/browser/http-CB9rQ7i_.d.ts +105 -0
- package/lib/browser/{index.d.cts → index.d.ts} +33 -38
- package/lib/browser/index.js +130 -0
- package/lib/browser/index.js.map +1 -0
- package/lib/browser/interceptor-dtJZ_9QT.d.ts +50 -0
- package/lib/browser/interceptors/WebSocket/index.d.ts +2 -0
- package/lib/browser/interceptors/WebSocket/{index.mjs → index.js} +40 -31
- package/lib/browser/interceptors/WebSocket/index.js.map +1 -0
- package/lib/browser/interceptors/XMLHttpRequest/web.d.ts +11 -0
- package/lib/browser/interceptors/XMLHttpRequest/web.js +2 -0
- package/lib/browser/interceptors/fetch/web.d.ts +14 -0
- package/lib/browser/interceptors/fetch/web.js +2 -0
- package/lib/browser/presets/browser.d.ts +11 -0
- package/lib/browser/presets/browser.js +12 -0
- package/lib/browser/presets/browser.js.map +1 -0
- package/lib/browser/{resolveWebSocketUrl-C83-x9iE.mjs → resolve-web-socket-url-CSvNPLGi.js} +3 -3
- package/lib/browser/resolve-web-socket-url-CSvNPLGi.js.map +1 -0
- package/lib/browser/web-BjVDkiX0.js +248 -0
- package/lib/browser/web-BjVDkiX0.js.map +1 -0
- package/lib/{node/XMLHttpRequest-DhupxLHX.mjs → browser/web-C2oKsT3Q.js} +328 -256
- package/lib/browser/web-C2oKsT3Q.js.map +1 -0
- package/lib/browser/{interceptors/WebSocket/index.d.cts → websocket-CC0nB0md.d.ts} +41 -33
- package/lib/node/batch-interceptor-ByEZVih3.js +119 -0
- package/lib/node/batch-interceptor-ByEZVih3.js.map +1 -0
- package/lib/node/batch-interceptor-CPjFK2td.d.ts +28 -0
- package/lib/node/buffer-utils-BvPY1Tc-.js +187 -0
- package/lib/node/buffer-utils-BvPY1Tc-.js.map +1 -0
- package/lib/node/fetch-utils-Dw1PsmtX.js +568 -0
- package/lib/node/fetch-utils-Dw1PsmtX.js.map +1 -0
- package/lib/node/has-configurable-global-CJCh_g1I.js +22 -0
- package/lib/node/has-configurable-global-CJCh_g1I.js.map +1 -0
- package/lib/node/http-CB9rQ7i_.d.ts +105 -0
- package/lib/{browser/interceptors/WebSocket/index.d.mts → node/index.d.ts} +120 -60
- package/lib/node/{index.mjs → index.js} +8 -11
- package/lib/node/index.js.map +1 -0
- package/lib/node/interceptor-dtJZ_9QT.d.ts +50 -0
- package/lib/node/interceptors/ClientRequest/index.d.ts +14 -0
- package/lib/node/interceptors/ClientRequest/index.js +67 -0
- package/lib/node/interceptors/ClientRequest/index.js.map +1 -0
- package/lib/node/interceptors/XMLHttpRequest/node.d.ts +12 -0
- package/lib/node/interceptors/XMLHttpRequest/node.js +74 -0
- package/lib/node/interceptors/XMLHttpRequest/node.js.map +1 -0
- package/lib/node/interceptors/fetch/node.d.ts +18 -0
- package/lib/node/interceptors/fetch/node.js +83 -0
- package/lib/node/interceptors/fetch/node.js.map +1 -0
- package/lib/node/interceptors/http/index.d.ts +14 -0
- package/lib/node/interceptors/http/index.js +32 -0
- package/lib/node/interceptors/http/index.js.map +1 -0
- package/lib/node/interceptors/net/index.d.ts +203 -0
- package/lib/node/interceptors/net/index.js +2 -0
- package/lib/node/llhttp/constants.cjs +485 -0
- package/lib/node/llhttp/constants.d.cts +957 -0
- package/lib/node/llhttp/llhttp.wasm +0 -0
- package/lib/node/net-DtMnyEeg.js +1388 -0
- package/lib/node/net-DtMnyEeg.js.map +1 -0
- package/lib/node/presets/node.d.ts +12 -0
- package/lib/node/presets/node.js +17 -0
- package/lib/node/presets/node.js.map +1 -0
- package/lib/node/{RemoteHttpInterceptor.d.cts → remote-http-interceptor.d.ts} +12 -11
- package/lib/node/{RemoteHttpInterceptor.mjs → remote-http-interceptor.js} +38 -33
- package/lib/node/remote-http-interceptor.js.map +1 -0
- package/lib/node/source-lP0yyEtA.js +1990 -0
- package/lib/node/source-lP0yyEtA.js.map +1 -0
- package/package.json +79 -118
- package/src/batch-interceptor.test.ts +475 -0
- package/src/batch-interceptor.ts +244 -0
- package/src/{createRequestId.test.ts → create-request-id.test.ts} +1 -2
- package/src/disposable.ts +13 -0
- package/src/events/http.ts +92 -0
- package/src/events/websocket.ts +47 -0
- package/src/glossary.ts +1 -27
- package/src/index.ts +18 -10
- package/src/interceptor.test.ts +279 -0
- package/src/interceptor.ts +139 -0
- package/src/interceptors/ClientRequest/index.test.ts +21 -39
- package/src/interceptors/ClientRequest/index.ts +65 -180
- package/src/interceptors/ClientRequest/utils/{recordRawHeaders.test.ts → record-raw-headers.test.ts} +1 -2
- package/src/interceptors/ClientRequest/utils/{recordRawHeaders.ts → record-raw-headers.ts} +29 -2
- package/src/interceptors/WebSocket/index.ts +34 -51
- package/src/interceptors/WebSocket/utils/{bindEvent.test.ts → bind-event.test.ts} +1 -2
- package/src/interceptors/WebSocket/utils/events.test.ts +0 -1
- package/src/interceptors/WebSocket/{WebSocketClassTransport.ts → web-socket-class-transport.ts} +3 -3
- package/src/interceptors/WebSocket/{WebSocketClientConnection.ts → web-socket-client-connection.ts} +4 -4
- package/src/interceptors/WebSocket/{WebSocketOverride.ts → web-socket-override.ts} +6 -7
- package/src/interceptors/WebSocket/{WebSocketServerConnection.ts → web-socket-server-connection.ts} +4 -4
- package/src/interceptors/WebSocket/{WebSocketTransport.ts → web-socket-transport.ts} +1 -1
- package/src/interceptors/XMLHttpRequest/node.ts +104 -0
- package/src/interceptors/XMLHttpRequest/polyfills/{ProgressEventPolyfill.ts → progress-event-polyfill.ts} +1 -1
- package/src/interceptors/XMLHttpRequest/utils/{concateArrayBuffer.test.ts → concat-array-buffer.test.ts} +1 -2
- package/src/interceptors/XMLHttpRequest/utils/{concatArrayBuffer.ts → concat-array-buffer.ts} +1 -1
- package/src/interceptors/XMLHttpRequest/utils/{createEvent.test.ts → create-event.test.ts} +3 -4
- package/src/interceptors/XMLHttpRequest/utils/{createEvent.ts → create-event.ts} +2 -2
- package/src/interceptors/XMLHttpRequest/utils/{createResponse.ts → create-response.ts} +1 -1
- package/src/interceptors/XMLHttpRequest/utils/{getBodyByteLength.test.ts → get-body-byte-length.test.ts} +1 -2
- package/src/interceptors/XMLHttpRequest/web.ts +34 -0
- package/src/interceptors/XMLHttpRequest/{XMLHttpRequestController.ts → xml-http-request-controller.ts} +363 -204
- package/src/interceptors/XMLHttpRequest/{XMLHttpRequestProxy.ts → xml-http-request-proxy.ts} +28 -25
- package/src/interceptors/fetch/node.ts +103 -0
- package/src/interceptors/fetch/utils/{followRedirect.ts → follow-redirect.ts} +1 -1
- package/src/interceptors/fetch/web.ts +217 -0
- package/src/interceptors/http/forward-events.test.ts +86 -0
- package/src/interceptors/http/forward-events.ts +139 -0
- package/src/interceptors/http/http-parser/index.ts +310 -0
- package/src/interceptors/http/http-parser/llhttp/constants.cjs +485 -0
- package/src/interceptors/http/http-parser/llhttp/constants.d.cts +957 -0
- package/src/interceptors/http/http-parser/llhttp/llhttp.wasm +0 -0
- package/src/interceptors/http/http-parser.ts +138 -0
- package/src/interceptors/http/index.ts +34 -0
- package/src/interceptors/http/source.ts +688 -0
- package/src/interceptors/net/index.ts +368 -0
- package/src/interceptors/net/socket-controller.ts +1476 -0
- package/src/interceptors/net/utils/address-info.ts +54 -0
- package/src/interceptors/net/utils/connection-options-to-url.ts +56 -0
- package/src/interceptors/net/utils/flush-writes.ts +57 -0
- package/src/interceptors/net/utils/get-tls-connect-options.ts +23 -0
- package/src/interceptors/net/utils/normalize-net-connect-args.test.ts +233 -0
- package/src/interceptors/net/utils/normalize-net-connect-args.ts +121 -0
- package/src/interceptors/net/utils/normalize-tls-connect-args.ts +50 -0
- package/src/presets/browser.ts +4 -4
- package/src/presets/node.ts +4 -4
- package/src/{RemoteHttpInterceptor.ts → remote-http-interceptor.ts} +55 -42
- package/src/request-context.ts +40 -0
- package/src/{RequestController.test.ts → request-controller.test.ts} +37 -3
- package/src/{RequestController.ts → request-controller.ts} +33 -11
- package/src/utils/{bufferUtils.test.ts → buffer-utils.test.ts} +1 -2
- package/src/utils/buffer-utils.ts +37 -0
- package/src/utils/{cloneObject.test.ts → clone-object.test.ts} +1 -2
- package/src/utils/{cloneObject.ts → clone-object.ts} +8 -8
- package/src/utils/{createProxy.test.ts → create-proxy.test.ts} +6 -4
- package/src/utils/{createProxy.ts → create-proxy.ts} +1 -1
- package/src/utils/{fetchUtils.test.ts → fetch-utils.test.ts} +1 -1
- package/src/utils/{fetchUtils.ts → fetch-utils.ts} +28 -3
- package/src/utils/{findPropertySource.test.ts → find-property-source.test.ts} +1 -2
- package/src/utils/{getCleanUrl.test.ts → get-clean-url.test.ts} +1 -2
- package/src/utils/{getUrlByRequestOptions.test.ts → get-url-by-request-options.test.ts} +4 -8
- package/src/utils/{getUrlByRequestOptions.ts → get-url-by-request-options.ts} +16 -16
- package/src/utils/{getValueBySymbol.test.ts → get-value-by-symbol.test.ts} +1 -2
- package/src/utils/{handleRequest.ts → handle-request.ts} +66 -47
- package/src/utils/{hasConfigurableGlobal.test.ts → has-configurable-global.test.ts} +1 -2
- package/src/utils/{hasConfigurableGlobal.ts → has-configurable-global.ts} +2 -4
- package/src/utils/{isObject.test.ts → is-object.test.ts} +1 -2
- package/src/utils/logger.test.ts +154 -0
- package/src/utils/logger.ts +154 -0
- package/src/utils/{parseJson.test.ts → parse-json.test.ts} +1 -2
- package/src/utils/{patchesRegistry.test.ts → patches-registry.test.ts} +1 -1
- package/src/utils/{patchesRegistry.ts → patches-registry.ts} +1 -1
- package/src/utils/{responseUtils.ts → response-utils.ts} +25 -2
- package/ClientRequest/package.json +0 -11
- package/RemoteHttpInterceptor/package.json +0 -11
- package/WebSocket/package.json +0 -12
- package/XMLHttpRequest/package.json +0 -12
- package/fetch/package.json +0 -12
- package/lib/browser/Interceptor-Deczogc8.d.cts +0 -65
- package/lib/browser/Interceptor-gqKgs-aF.d.mts +0 -65
- package/lib/browser/XMLHttpRequest-B11I9TBx.cjs +0 -751
- package/lib/browser/XMLHttpRequest-B11I9TBx.cjs.map +0 -1
- package/lib/browser/XMLHttpRequest-DHEkSoRN.mjs +0 -746
- package/lib/browser/XMLHttpRequest-DHEkSoRN.mjs.map +0 -1
- package/lib/browser/bufferUtils-BiiO6HZv.mjs.map +0 -1
- package/lib/browser/bufferUtils-Uc0eRItL.cjs +0 -38
- package/lib/browser/bufferUtils-Uc0eRItL.cjs.map +0 -1
- package/lib/browser/createRequestId-DOf8Ktjs.cjs +0 -205
- package/lib/browser/createRequestId-DOf8Ktjs.cjs.map +0 -1
- package/lib/browser/createRequestId-DYCsFHOi.mjs +0 -170
- package/lib/browser/createRequestId-DYCsFHOi.mjs.map +0 -1
- package/lib/browser/fetch-BJwfdses.mjs +0 -236
- package/lib/browser/fetch-BJwfdses.mjs.map +0 -1
- package/lib/browser/fetch-M8iXkZ3L.cjs +0 -241
- package/lib/browser/fetch-M8iXkZ3L.cjs.map +0 -1
- package/lib/browser/getRawRequest-B1BqgWG6.mjs.map +0 -1
- package/lib/browser/getRawRequest-DdfaiPVH.cjs +0 -376
- package/lib/browser/getRawRequest-DdfaiPVH.cjs.map +0 -1
- package/lib/browser/glossary-1lhZx6Aw.d.cts +0 -69
- package/lib/browser/glossary-nkHWcwvY.d.mts +0 -69
- package/lib/browser/handleRequest-1Yqu_ho_.mjs +0 -178
- package/lib/browser/handleRequest-1Yqu_ho_.mjs.map +0 -1
- package/lib/browser/handleRequest-Cz4_wmQ9.cjs +0 -189
- package/lib/browser/handleRequest-Cz4_wmQ9.cjs.map +0 -1
- package/lib/browser/hasConfigurableGlobal-C8zq1MCg.mjs +0 -109
- package/lib/browser/hasConfigurableGlobal-C8zq1MCg.mjs.map +0 -1
- package/lib/browser/hasConfigurableGlobal-CS7adEvV.cjs +0 -126
- package/lib/browser/hasConfigurableGlobal-CS7adEvV.cjs.map +0 -1
- package/lib/browser/index.cjs +0 -70
- package/lib/browser/index.cjs.map +0 -1
- package/lib/browser/index.d.mts +0 -125
- package/lib/browser/index.mjs +0 -56
- package/lib/browser/index.mjs.map +0 -1
- package/lib/browser/interceptors/WebSocket/index.cjs +0 -618
- package/lib/browser/interceptors/WebSocket/index.cjs.map +0 -1
- package/lib/browser/interceptors/WebSocket/index.mjs.map +0 -1
- package/lib/browser/interceptors/XMLHttpRequest/index.cjs +0 -8
- package/lib/browser/interceptors/XMLHttpRequest/index.d.cts +0 -15
- package/lib/browser/interceptors/XMLHttpRequest/index.d.mts +0 -15
- package/lib/browser/interceptors/XMLHttpRequest/index.mjs +0 -8
- package/lib/browser/interceptors/fetch/index.cjs +0 -7
- package/lib/browser/interceptors/fetch/index.d.cts +0 -13
- package/lib/browser/interceptors/fetch/index.d.mts +0 -13
- package/lib/browser/interceptors/fetch/index.mjs +0 -7
- package/lib/browser/presets/browser.cjs +0 -18
- package/lib/browser/presets/browser.cjs.map +0 -1
- package/lib/browser/presets/browser.d.cts +0 -12
- package/lib/browser/presets/browser.d.mts +0 -14
- package/lib/browser/presets/browser.mjs +0 -18
- package/lib/browser/presets/browser.mjs.map +0 -1
- package/lib/browser/resolveWebSocketUrl-6K6EgqsA.cjs +0 -31
- package/lib/browser/resolveWebSocketUrl-6K6EgqsA.cjs.map +0 -1
- package/lib/browser/resolveWebSocketUrl-C83-x9iE.mjs.map +0 -1
- package/lib/node/BatchInterceptor-DdMNfSUY.mjs +0 -44
- package/lib/node/BatchInterceptor-DdMNfSUY.mjs.map +0 -1
- package/lib/node/BatchInterceptor-KKF8Q47I.d.cts +0 -26
- package/lib/node/BatchInterceptor-Z1lwK23r.cjs +0 -49
- package/lib/node/BatchInterceptor-Z1lwK23r.cjs.map +0 -1
- package/lib/node/BatchInterceptor-rSr-NH_H.d.mts +0 -26
- package/lib/node/ClientRequest-DFs7FPNi.cjs +0 -1058
- package/lib/node/ClientRequest-DFs7FPNi.cjs.map +0 -1
- package/lib/node/ClientRequest-dRpI9v1o.mjs +0 -1049
- package/lib/node/ClientRequest-dRpI9v1o.mjs.map +0 -1
- package/lib/node/Interceptor-BsZ21ue0.d.cts +0 -132
- package/lib/node/Interceptor-soD-WpQO.d.mts +0 -132
- package/lib/node/RemoteHttpInterceptor.cjs +0 -155
- package/lib/node/RemoteHttpInterceptor.cjs.map +0 -1
- package/lib/node/RemoteHttpInterceptor.d.mts +0 -39
- package/lib/node/RemoteHttpInterceptor.mjs.map +0 -1
- package/lib/node/XMLHttpRequest-DhupxLHX.mjs.map +0 -1
- package/lib/node/XMLHttpRequest-Dyi6ahGz.cjs +0 -752
- package/lib/node/XMLHttpRequest-Dyi6ahGz.cjs.map +0 -1
- package/lib/node/bufferUtils-DxPxwff_.mjs +0 -20
- package/lib/node/bufferUtils-DxPxwff_.mjs.map +0 -1
- package/lib/node/bufferUtils-S5_-2eN4.cjs +0 -38
- package/lib/node/bufferUtils-S5_-2eN4.cjs.map +0 -1
- package/lib/node/chunk-CbDLau6x.cjs +0 -34
- package/lib/node/fetch-BqMcbuYR.mjs +0 -252
- package/lib/node/fetch-BqMcbuYR.mjs.map +0 -1
- package/lib/node/fetch-aQJu1Gf_.cjs +0 -259
- package/lib/node/fetch-aQJu1Gf_.cjs.map +0 -1
- package/lib/node/fetchUtils-BKJ1XmiO.mjs +0 -480
- package/lib/node/fetchUtils-BKJ1XmiO.mjs.map +0 -1
- package/lib/node/fetchUtils-umV5xXBy.cjs +0 -546
- package/lib/node/fetchUtils-umV5xXBy.cjs.map +0 -1
- package/lib/node/getRawRequest-B6znU6il.cjs +0 -36
- package/lib/node/getRawRequest-B6znU6il.cjs.map +0 -1
- package/lib/node/getRawRequest-C2-1urzA.mjs +0 -24
- package/lib/node/getRawRequest-C2-1urzA.mjs.map +0 -1
- package/lib/node/handleRequest-DCLzePtS.mjs +0 -190
- package/lib/node/handleRequest-DCLzePtS.mjs.map +0 -1
- package/lib/node/handleRequest-DVOthWJo.cjs +0 -220
- package/lib/node/handleRequest-DVOthWJo.cjs.map +0 -1
- package/lib/node/hasConfigurableGlobal-BiTmog1u.mjs.map +0 -1
- package/lib/node/hasConfigurableGlobal-MjY06_Ok.cjs +0 -108
- package/lib/node/hasConfigurableGlobal-MjY06_Ok.cjs.map +0 -1
- package/lib/node/index-BJ5E5aW-.d.cts +0 -113
- package/lib/node/index-DfoF45ih.d.mts +0 -113
- package/lib/node/index.cjs +0 -53
- package/lib/node/index.cjs.map +0 -1
- package/lib/node/index.d.cts +0 -104
- package/lib/node/index.d.mts +0 -104
- package/lib/node/index.mjs.map +0 -1
- package/lib/node/interceptors/ClientRequest/index.cjs +0 -6
- package/lib/node/interceptors/ClientRequest/index.d.cts +0 -2
- package/lib/node/interceptors/ClientRequest/index.d.mts +0 -3
- package/lib/node/interceptors/ClientRequest/index.mjs +0 -6
- package/lib/node/interceptors/XMLHttpRequest/index.cjs +0 -7
- package/lib/node/interceptors/XMLHttpRequest/index.d.cts +0 -14
- package/lib/node/interceptors/XMLHttpRequest/index.d.mts +0 -14
- package/lib/node/interceptors/XMLHttpRequest/index.mjs +0 -7
- package/lib/node/interceptors/fetch/index.cjs +0 -6
- package/lib/node/interceptors/fetch/index.d.cts +0 -12
- package/lib/node/interceptors/fetch/index.d.mts +0 -12
- package/lib/node/interceptors/fetch/index.mjs +0 -6
- package/lib/node/node-DIKcnzhK.cjs +0 -39
- package/lib/node/node-DIKcnzhK.cjs.map +0 -1
- package/lib/node/node-lsdNwZEW.mjs +0 -27
- package/lib/node/node-lsdNwZEW.mjs.map +0 -1
- package/lib/node/presets/node.cjs +0 -23
- package/lib/node/presets/node.cjs.map +0 -1
- package/lib/node/presets/node.d.cts +0 -13
- package/lib/node/presets/node.d.mts +0 -15
- package/lib/node/presets/node.mjs +0 -23
- package/lib/node/presets/node.mjs.map +0 -1
- package/lib/node/utils/node/index.cjs +0 -4
- package/lib/node/utils/node/index.d.cts +0 -16
- package/lib/node/utils/node/index.d.mts +0 -16
- package/lib/node/utils/node/index.mjs +0 -3
- package/presets/browser/package.json +0 -5
- package/presets/node/package.json +0 -11
- package/src/BatchInterceptor.test.ts +0 -255
- package/src/BatchInterceptor.ts +0 -95
- package/src/Interceptor.test.ts +0 -205
- package/src/Interceptor.ts +0 -249
- package/src/getRawRequest.ts +0 -21
- package/src/interceptors/ClientRequest/MockHttpSocket.ts +0 -724
- package/src/interceptors/ClientRequest/agents.ts +0 -110
- package/src/interceptors/ClientRequest/utils/getIncomingMessageBody.test.ts +0 -54
- package/src/interceptors/ClientRequest/utils/getIncomingMessageBody.ts +0 -45
- package/src/interceptors/ClientRequest/utils/normalizeClientRequestArgs.test.ts +0 -427
- package/src/interceptors/ClientRequest/utils/normalizeClientRequestArgs.ts +0 -268
- package/src/interceptors/ClientRequest/utils/parserUtils.ts +0 -48
- package/src/interceptors/Socket/MockSocket.test.ts +0 -264
- package/src/interceptors/Socket/MockSocket.ts +0 -58
- package/src/interceptors/Socket/utils/baseUrlFromConnectionOptions.ts +0 -26
- package/src/interceptors/Socket/utils/normalizeSocketWriteArgs.test.ts +0 -52
- package/src/interceptors/Socket/utils/normalizeSocketWriteArgs.ts +0 -33
- package/src/interceptors/XMLHttpRequest/index.ts +0 -40
- package/src/interceptors/fetch/index.ts +0 -203
- package/src/utils/bufferUtils.ts +0 -22
- package/src/utils/canParseUrl.ts +0 -13
- package/src/utils/emitAsync.ts +0 -25
- package/src/utils/nextTick.ts +0 -11
- package/src/utils/node/index.ts +0 -39
- /package/src/{createRequestId.ts → create-request-id.ts} +0 -0
- /package/src/{InterceptorError.ts → interceptor-error.ts} +0 -0
- /package/src/interceptors/WebSocket/utils/{bindEvent.ts → bind-event.ts} +0 -0
- /package/src/interceptors/XMLHttpRequest/polyfills/{EventPolyfill.ts → event-polyfill.ts} +0 -0
- /package/src/interceptors/XMLHttpRequest/utils/{getBodyByteLength.ts → get-body-byte-length.ts} +0 -0
- /package/src/interceptors/XMLHttpRequest/utils/{isDomParserSupportedType.ts → is-dom-parser-supported-type.ts} +0 -0
- /package/src/interceptors/fetch/utils/{createNetworkError.ts → create-network-error.ts} +0 -0
- /package/src/utils/{findPropertySource.ts → find-property-source.ts} +0 -0
- /package/src/utils/{getCleanUrl.ts → get-clean-url.ts} +0 -0
- /package/src/utils/{getValueBySymbol.ts → get-value-by-symbol.ts} +0 -0
- /package/src/utils/{isNodeLikeError.ts → is-node-like-error.ts} +0 -0
- /package/src/utils/{isObject.ts → is-object.ts} +0 -0
- /package/src/utils/{isPropertyAccessible.ts → is-property-accessible.ts} +0 -0
- /package/src/utils/{parseJson.ts → parse-json.ts} +0 -0
- /package/src/utils/{resolveWebSocketUrl.ts → resolve-web-socket-url.ts} +0 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import net from 'node:net'
|
|
2
|
+
import { NetworkConnectionOptions } from './normalize-net-connect-args'
|
|
3
|
+
|
|
4
|
+
export function getAddressInfoByConnectionOptions(
|
|
5
|
+
options?: NetworkConnectionOptions
|
|
6
|
+
): ReturnType<net.Socket['address']> {
|
|
7
|
+
if (options == null) {
|
|
8
|
+
return {}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const isIPv6 = options.family === 6 || net.isIPv6(options.host || '')
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
address: isIPv6 ? '::1' : '127.0.0.1',
|
|
15
|
+
/**
|
|
16
|
+
* @note Coerce the port to a number. Connection options may
|
|
17
|
+
* describe it as a string (e.g. when created from a URL), while
|
|
18
|
+
* the address info always reports a numeric port.
|
|
19
|
+
*/
|
|
20
|
+
port: Number(options.port) || (options.protocol === 'https:' ? 443 : 80),
|
|
21
|
+
family: isIPv6 ? 'IPv6' : 'IPv4',
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Get the local address info for the given connection options.
|
|
27
|
+
* This describes the client-side end of the connection: the socket
|
|
28
|
+
* is bound to the loopback interface and an ephemeral port, the same
|
|
29
|
+
* way the operating system binds an outgoing connection.
|
|
30
|
+
*/
|
|
31
|
+
export function getLocalAddressInfoByConnectionOptions(
|
|
32
|
+
options?: NetworkConnectionOptions
|
|
33
|
+
): ReturnType<net.Socket['address']> {
|
|
34
|
+
if (options == null) {
|
|
35
|
+
return {}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const isIPv6 = options.family === 6 || net.isIPv6(options.host || '')
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
address: options.localAddress || (isIPv6 ? '::1' : '127.0.0.1'),
|
|
42
|
+
port: options.localPort || getEphemeralPort(),
|
|
43
|
+
family: isIPv6 ? 'IPv6' : 'IPv4',
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Get a random port from the ephemeral range (IANA: 49152-65535),
|
|
49
|
+
* the range the operating system draws from when binding an
|
|
50
|
+
* outgoing connection.
|
|
51
|
+
*/
|
|
52
|
+
function getEphemeralPort(): number {
|
|
53
|
+
return 49152 + Math.floor(Math.random() * (65535 - 49152 + 1))
|
|
54
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import net from 'node:net'
|
|
2
|
+
import tls from 'node:tls'
|
|
3
|
+
import { NetworkConnectionOptions } from './normalize-net-connect-args'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a `URL` instance out of the `net.connect()` options.
|
|
7
|
+
* @note This implies that the passed connection is an HTTP connection.
|
|
8
|
+
*/
|
|
9
|
+
export function connectionOptionsToUrl(
|
|
10
|
+
options: NetworkConnectionOptions,
|
|
11
|
+
socket: net.Socket
|
|
12
|
+
): URL {
|
|
13
|
+
const isIPv6 = net.isIPv6(options.host || '')
|
|
14
|
+
const protocol =
|
|
15
|
+
socket instanceof tls.TLSSocket
|
|
16
|
+
? 'https:'
|
|
17
|
+
: getProtocolByConnectionOptions(options)
|
|
18
|
+
const host = options.host || 'localhost'
|
|
19
|
+
|
|
20
|
+
const url = new URL(`${protocol}//${isIPv6 ? `[${host}]` : host}`)
|
|
21
|
+
|
|
22
|
+
if (options.path) {
|
|
23
|
+
url.pathname = options.path
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (options.port) {
|
|
27
|
+
url.port = options.port.toString()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (options.auth) {
|
|
31
|
+
const [username, password] = options.auth.split(':')
|
|
32
|
+
/**
|
|
33
|
+
* Authentication options are provided as plain values.
|
|
34
|
+
* Encode them to form a valid URL.
|
|
35
|
+
* @see https://github.com/nodejs/node/blob/f3adc11e37b8bfaaa026ea85c1cf22e3a0e29ae9/lib/internal/url.js#L1452
|
|
36
|
+
*/
|
|
37
|
+
url.username = encodeURIComponent(username)
|
|
38
|
+
url.password = encodeURIComponent(password)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return url
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function getProtocolByConnectionOptions(
|
|
45
|
+
options: NetworkConnectionOptions
|
|
46
|
+
): 'https:' | 'http:' | (string & {}) {
|
|
47
|
+
if (options.protocol) {
|
|
48
|
+
return options.protocol
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (options.port === 443) {
|
|
52
|
+
return 'https:'
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return 'http:'
|
|
56
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import net from 'node:net'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Write the given pending data to the socket using its public
|
|
5
|
+
* "write()" method. Unlike direct "_writeGeneric()" calls, public
|
|
6
|
+
* writes go through the "Writable" queue that only dispatches the
|
|
7
|
+
* next write once the previous one completes. TLS sockets rely on
|
|
8
|
+
* that serialization: their "TLSWrap" handle supports a single
|
|
9
|
+
* write in flight and crashes the process with a native
|
|
10
|
+
* "Assertion failed: !current_write_" abort when writes overlap
|
|
11
|
+
* (e.g. multiple direct "_writeGeneric()" calls issued on a
|
|
12
|
+
* connecting socket replay back-to-back on "connect").
|
|
13
|
+
*/
|
|
14
|
+
export function writePendingData(
|
|
15
|
+
socket: net.Socket,
|
|
16
|
+
data: NonNullable<net.Socket['_pendingData']>,
|
|
17
|
+
encoding: BufferEncoding,
|
|
18
|
+
callback?: (error?: Error | null) => void
|
|
19
|
+
): void {
|
|
20
|
+
if (Array.isArray(data)) {
|
|
21
|
+
for (let index = 0; index < data.length; index++) {
|
|
22
|
+
const entry = data[index]
|
|
23
|
+
const isLastEntry = index === data.length - 1
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @note Per-entry callbacks are intentionally ignored, the same
|
|
27
|
+
* way "writevGeneric()" only honors the batch-level callback.
|
|
28
|
+
*/
|
|
29
|
+
if (isLastEntry) {
|
|
30
|
+
socket.write(entry.chunk, entry.encoding, callback)
|
|
31
|
+
} else {
|
|
32
|
+
socket.write(entry.chunk, entry.encoding)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
socket.write(data, encoding, callback)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function unwrapPendingData(
|
|
43
|
+
data: NonNullable<net.Socket['_pendingData']>,
|
|
44
|
+
callback: (
|
|
45
|
+
chunk: string | Buffer,
|
|
46
|
+
encoding?: BufferEncoding,
|
|
47
|
+
callback?: (error?: Error | null) => void
|
|
48
|
+
) => void
|
|
49
|
+
) {
|
|
50
|
+
if (Array.isArray(data)) {
|
|
51
|
+
for (const entry of data) {
|
|
52
|
+
callback(entry.chunk, entry.encoding, entry.callback)
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
callback(data)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type tls from 'node:tls'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the original options the given TLS socket was created with.
|
|
5
|
+
* The original `tls.connect()` stores them on the socket instance
|
|
6
|
+
* under an internal symbol before connecting its transport.
|
|
7
|
+
* @see https://github.com/nodejs/node/blob/3178a762d6a2b1a37b74f02266eea0f3d86603f1/lib/_tls_wrap.js#L1690
|
|
8
|
+
*/
|
|
9
|
+
export function getTlsConnectOptions(
|
|
10
|
+
socket: tls.TLSSocket
|
|
11
|
+
): tls.ConnectionOptions | undefined {
|
|
12
|
+
const kConnectOptions = Object.getOwnPropertySymbols(socket).find(
|
|
13
|
+
(symbol) => {
|
|
14
|
+
return symbol.description === 'connect-options'
|
|
15
|
+
}
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
if (kConnectOptions == null) {
|
|
19
|
+
return undefined
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return Reflect.get(socket, kConnectOptions)
|
|
23
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeNetConnectArgs,
|
|
3
|
+
type NetConnectArgs,
|
|
4
|
+
} from './normalize-net-connect-args'
|
|
5
|
+
|
|
6
|
+
it('normalizes an empty arguments list', () => {
|
|
7
|
+
expect(normalizeNetConnectArgs([])).toEqual([{ path: '' }, null])
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('normalizes "(port)"', () => {
|
|
11
|
+
expect(normalizeNetConnectArgs([8080])).toEqual([
|
|
12
|
+
{
|
|
13
|
+
port: 8080,
|
|
14
|
+
path: '',
|
|
15
|
+
host: undefined,
|
|
16
|
+
},
|
|
17
|
+
null,
|
|
18
|
+
])
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('normalizes "(port, callback)"', () => {
|
|
22
|
+
const callback = () => {}
|
|
23
|
+
|
|
24
|
+
expect(normalizeNetConnectArgs([8080, callback])).toEqual([
|
|
25
|
+
{
|
|
26
|
+
port: 8080,
|
|
27
|
+
path: '',
|
|
28
|
+
host: undefined,
|
|
29
|
+
},
|
|
30
|
+
callback,
|
|
31
|
+
])
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('normalizes "(port, host)"', () => {
|
|
35
|
+
expect(normalizeNetConnectArgs([8080, 'example.com'])).toEqual([
|
|
36
|
+
{
|
|
37
|
+
port: 8080,
|
|
38
|
+
path: '',
|
|
39
|
+
host: 'example.com',
|
|
40
|
+
},
|
|
41
|
+
null,
|
|
42
|
+
])
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('normalizes "(port, host, callback)"', () => {
|
|
46
|
+
const callback = () => {}
|
|
47
|
+
|
|
48
|
+
expect(normalizeNetConnectArgs([8080, 'example.com', callback])).toEqual([
|
|
49
|
+
{
|
|
50
|
+
port: 8080,
|
|
51
|
+
path: '',
|
|
52
|
+
host: 'example.com',
|
|
53
|
+
},
|
|
54
|
+
callback,
|
|
55
|
+
])
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('normalizes a zero port', () => {
|
|
59
|
+
expect(normalizeNetConnectArgs([0, 'example.com'])).toEqual([
|
|
60
|
+
{
|
|
61
|
+
port: 0,
|
|
62
|
+
path: '',
|
|
63
|
+
host: 'example.com',
|
|
64
|
+
},
|
|
65
|
+
null,
|
|
66
|
+
])
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('normalizes "(options)"', () => {
|
|
70
|
+
expect(
|
|
71
|
+
normalizeNetConnectArgs([{ port: 8080, host: 'example.com' }])
|
|
72
|
+
).toEqual([
|
|
73
|
+
{
|
|
74
|
+
port: 8080,
|
|
75
|
+
path: '',
|
|
76
|
+
host: 'example.com',
|
|
77
|
+
auth: undefined,
|
|
78
|
+
family: undefined,
|
|
79
|
+
session: undefined,
|
|
80
|
+
localAddress: undefined,
|
|
81
|
+
localPort: undefined,
|
|
82
|
+
},
|
|
83
|
+
null,
|
|
84
|
+
])
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('normalizes "(options, callback)"', () => {
|
|
88
|
+
const callback = () => {}
|
|
89
|
+
|
|
90
|
+
expect(
|
|
91
|
+
normalizeNetConnectArgs([{ port: 8080, host: 'example.com' }, callback])
|
|
92
|
+
).toEqual([
|
|
93
|
+
{
|
|
94
|
+
port: 8080,
|
|
95
|
+
path: '',
|
|
96
|
+
host: 'example.com',
|
|
97
|
+
},
|
|
98
|
+
callback,
|
|
99
|
+
])
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('normalizes "(options)" with connection-specific options', () => {
|
|
103
|
+
const session = Buffer.from('session')
|
|
104
|
+
|
|
105
|
+
expect(
|
|
106
|
+
normalizeNetConnectArgs([
|
|
107
|
+
{
|
|
108
|
+
port: 8080,
|
|
109
|
+
host: 'example.com',
|
|
110
|
+
family: 6,
|
|
111
|
+
localAddress: '10.0.0.1',
|
|
112
|
+
localPort: 34567,
|
|
113
|
+
},
|
|
114
|
+
])
|
|
115
|
+
).toEqual([
|
|
116
|
+
{
|
|
117
|
+
port: 8080,
|
|
118
|
+
path: '',
|
|
119
|
+
host: 'example.com',
|
|
120
|
+
family: 6,
|
|
121
|
+
localAddress: '10.0.0.1',
|
|
122
|
+
localPort: 34567,
|
|
123
|
+
},
|
|
124
|
+
null,
|
|
125
|
+
])
|
|
126
|
+
|
|
127
|
+
expect(
|
|
128
|
+
normalizeNetConnectArgs([
|
|
129
|
+
// The type definitions of "net.connect()" omit
|
|
130
|
+
// the TLS-specific options ("auth", "session").
|
|
131
|
+
Object.assign({ port: 8080 }, { auth: 'user:pass', session }),
|
|
132
|
+
])
|
|
133
|
+
).toEqual([
|
|
134
|
+
expect.objectContaining({
|
|
135
|
+
port: 8080,
|
|
136
|
+
auth: 'user:pass',
|
|
137
|
+
session,
|
|
138
|
+
}),
|
|
139
|
+
null,
|
|
140
|
+
])
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it('normalizes "(options)" with the "path" option', () => {
|
|
144
|
+
expect(normalizeNetConnectArgs([{ path: '/tmp/service.sock' }])).toEqual([
|
|
145
|
+
{
|
|
146
|
+
path: '/tmp/service.sock',
|
|
147
|
+
auth: undefined,
|
|
148
|
+
family: undefined,
|
|
149
|
+
session: undefined,
|
|
150
|
+
},
|
|
151
|
+
null,
|
|
152
|
+
])
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
it('normalizes "(path)"', () => {
|
|
156
|
+
expect(normalizeNetConnectArgs(['/tmp/service.sock'])).toEqual([
|
|
157
|
+
{
|
|
158
|
+
path: '/tmp/service.sock',
|
|
159
|
+
},
|
|
160
|
+
null,
|
|
161
|
+
])
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
it('normalizes "(path, callback)"', () => {
|
|
165
|
+
const callback = () => {}
|
|
166
|
+
|
|
167
|
+
expect(normalizeNetConnectArgs(['/tmp/service.sock', callback])).toEqual([
|
|
168
|
+
{
|
|
169
|
+
path: '/tmp/service.sock',
|
|
170
|
+
},
|
|
171
|
+
callback,
|
|
172
|
+
])
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* @note Node.js does not support URL arguments and reads them
|
|
177
|
+
* as plain options objects. Reproduce that reading exactly:
|
|
178
|
+
* "url.port" is a string, "url.host" includes the port.
|
|
179
|
+
*/
|
|
180
|
+
it('treats "(url)" as a plain options object, like Node.js', () => {
|
|
181
|
+
expect(
|
|
182
|
+
normalizeNetConnectArgs([new URL('http://example.com:8080/path?query=1')])
|
|
183
|
+
).toEqual([
|
|
184
|
+
{
|
|
185
|
+
path: '',
|
|
186
|
+
port: '8080',
|
|
187
|
+
host: 'example.com:8080',
|
|
188
|
+
},
|
|
189
|
+
null,
|
|
190
|
+
])
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
it('treats a port-less "(url)" as a plain options object, like Node.js', () => {
|
|
194
|
+
expect(normalizeNetConnectArgs([new URL('http://example.com/')])).toEqual([
|
|
195
|
+
{
|
|
196
|
+
path: '',
|
|
197
|
+
port: '',
|
|
198
|
+
host: 'example.com',
|
|
199
|
+
},
|
|
200
|
+
null,
|
|
201
|
+
])
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
it('normalizes "(url, callback)"', () => {
|
|
205
|
+
const callback = () => {}
|
|
206
|
+
|
|
207
|
+
expect(
|
|
208
|
+
normalizeNetConnectArgs([new URL('http://example.com:8080/'), callback])
|
|
209
|
+
).toEqual([
|
|
210
|
+
expect.objectContaining({
|
|
211
|
+
port: '8080',
|
|
212
|
+
host: 'example.com:8080',
|
|
213
|
+
}),
|
|
214
|
+
callback,
|
|
215
|
+
])
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
it('returns a new options object for the "(options)" signature', () => {
|
|
219
|
+
const inputOptions = { port: 8080, host: 'example.com' }
|
|
220
|
+
const [normalizedOptions] = normalizeNetConnectArgs([inputOptions])
|
|
221
|
+
|
|
222
|
+
expect(normalizedOptions).not.toBe(inputOptions)
|
|
223
|
+
|
|
224
|
+
// Modifying the normalized options must not affect the input.
|
|
225
|
+
normalizedOptions.host = 'changed.com'
|
|
226
|
+
expect(inputOptions).toEqual({ port: 8080, host: 'example.com' })
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
it('throws on invalid arguments', () => {
|
|
230
|
+
expect(() => {
|
|
231
|
+
return normalizeNetConnectArgs([true] as unknown as NetConnectArgs)
|
|
232
|
+
}).toThrow('Invalid arguments passed to net.connect: true')
|
|
233
|
+
})
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import net from 'node:net'
|
|
2
|
+
|
|
3
|
+
export interface NetworkConnectionOptions {
|
|
4
|
+
/**
|
|
5
|
+
* @note The port may be a string when a URL is (incorrectly) passed
|
|
6
|
+
* to `net.connect()`. Node.js reads URLs as plain options objects.
|
|
7
|
+
*/
|
|
8
|
+
port?: number | string | null
|
|
9
|
+
path: string | null
|
|
10
|
+
host?: string | null
|
|
11
|
+
protocol?: string | null
|
|
12
|
+
auth?: string | null
|
|
13
|
+
family?: number | null
|
|
14
|
+
hints?: number | null
|
|
15
|
+
session?: Buffer
|
|
16
|
+
localAddress?: string | null
|
|
17
|
+
localPort?: number | null
|
|
18
|
+
timeout?: number
|
|
19
|
+
lookup?: net.LookupFunction
|
|
20
|
+
allowHalfOpen?: boolean | null
|
|
21
|
+
noDelay?: boolean | null
|
|
22
|
+
keepAlive?: boolean | null
|
|
23
|
+
keepAliveInitialDelay?: number | null
|
|
24
|
+
autoSelectFamily?: boolean | null
|
|
25
|
+
autoSelectFamilyAttemptTimeout?: number | null
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type NetConnectArgs =
|
|
29
|
+
| []
|
|
30
|
+
| [options: net.NetConnectOpts, callback?: () => void]
|
|
31
|
+
| [url: URL, callback?: () => void]
|
|
32
|
+
| [port: number, host?: string, callback?: () => void]
|
|
33
|
+
| [port: number, callback?: () => void]
|
|
34
|
+
| [path: string, callback?: () => void]
|
|
35
|
+
|
|
36
|
+
export type NormalizedNetConnectArgs = [
|
|
37
|
+
options: NetworkConnectionOptions,
|
|
38
|
+
callback: (() => void) | null,
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Normalizes the arguments passed to `net.connect()`.
|
|
43
|
+
*/
|
|
44
|
+
export function normalizeNetConnectArgs(
|
|
45
|
+
args: NetConnectArgs
|
|
46
|
+
): NormalizedNetConnectArgs {
|
|
47
|
+
if (args.length === 0) {
|
|
48
|
+
return [{ path: '' }, null]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const callback = typeof args[1] === 'function' ? args[1] : args[2] || null
|
|
52
|
+
|
|
53
|
+
if (typeof args[0] === 'string') {
|
|
54
|
+
return [{ path: args[0] }, callback]
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (typeof args[0] === 'number') {
|
|
58
|
+
return [
|
|
59
|
+
{
|
|
60
|
+
port: args[0],
|
|
61
|
+
path: '',
|
|
62
|
+
/**
|
|
63
|
+
* @note The host is optional in the "(port[, host][, callback])"
|
|
64
|
+
* signatures and defaults to "localhost" in Node.js.
|
|
65
|
+
*/
|
|
66
|
+
host: typeof args[1] === 'string' ? args[1] : undefined,
|
|
67
|
+
},
|
|
68
|
+
callback,
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (typeof args[0] === 'object') {
|
|
73
|
+
/**
|
|
74
|
+
* @note URL arguments receive no special treatment on purpose.
|
|
75
|
+
* Node.js does not support them and reads a given URL as a plain
|
|
76
|
+
* options object (e.g. "url.port" is a string, "url.host" includes
|
|
77
|
+
* the port). The "port" branch below reproduces that reading.
|
|
78
|
+
*/
|
|
79
|
+
if ('port' in args[0]) {
|
|
80
|
+
return [
|
|
81
|
+
{
|
|
82
|
+
path: '',
|
|
83
|
+
port: Reflect.get(args[0], 'port'),
|
|
84
|
+
host: Reflect.get(args[0], 'host'),
|
|
85
|
+
auth: Reflect.get(args[0], 'auth'),
|
|
86
|
+
family: Reflect.get(args[0], 'family'),
|
|
87
|
+
hints: Reflect.get(args[0], 'hints'),
|
|
88
|
+
session: Reflect.get(args[0], 'session'),
|
|
89
|
+
localAddress: Reflect.get(args[0], 'localAddress'),
|
|
90
|
+
localPort: Reflect.get(args[0], 'localPort'),
|
|
91
|
+
timeout: Reflect.get(args[0], 'timeout'),
|
|
92
|
+
lookup: Reflect.get(args[0], 'lookup'),
|
|
93
|
+
allowHalfOpen: Reflect.get(args[0], 'allowHalfOpen'),
|
|
94
|
+
noDelay: Reflect.get(args[0], 'noDelay'),
|
|
95
|
+
keepAlive: Reflect.get(args[0], 'keepAlive'),
|
|
96
|
+
keepAliveInitialDelay: Reflect.get(args[0], 'keepAliveInitialDelay'),
|
|
97
|
+
autoSelectFamily: Reflect.get(args[0], 'autoSelectFamily'),
|
|
98
|
+
autoSelectFamilyAttemptTimeout: Reflect.get(
|
|
99
|
+
args[0],
|
|
100
|
+
'autoSelectFamilyAttemptTimeout'
|
|
101
|
+
),
|
|
102
|
+
},
|
|
103
|
+
callback,
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return [
|
|
108
|
+
{
|
|
109
|
+
path: args[0].path || '',
|
|
110
|
+
family: Reflect.get(args[0], 'family'),
|
|
111
|
+
session: Reflect.get(args[0], 'session'),
|
|
112
|
+
auth: Reflect.get(args[0], 'auth'),
|
|
113
|
+
timeout: Reflect.get(args[0], 'timeout'),
|
|
114
|
+
allowHalfOpen: Reflect.get(args[0], 'allowHalfOpen'),
|
|
115
|
+
},
|
|
116
|
+
callback,
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
throw new Error(`Invalid arguments passed to net.connect: ${args}`)
|
|
121
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import tls from 'node:tls'
|
|
2
|
+
import {
|
|
3
|
+
type NetConnectArgs,
|
|
4
|
+
type NetworkConnectionOptions,
|
|
5
|
+
normalizeNetConnectArgs,
|
|
6
|
+
} from './normalize-net-connect-args'
|
|
7
|
+
|
|
8
|
+
type TlsConnectArgs =
|
|
9
|
+
| []
|
|
10
|
+
| [options: tls.ConnectionOptions, callback?: () => void]
|
|
11
|
+
| [url: URL, callback?: () => void]
|
|
12
|
+
| [port: number, options?: tls.ConnectionOptions, callback?: () => void]
|
|
13
|
+
| [
|
|
14
|
+
port: number,
|
|
15
|
+
host?: string,
|
|
16
|
+
options?: tls.ConnectionOptions,
|
|
17
|
+
callback?: () => void,
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
export type TlsConnectionOptions = tls.ConnectionOptions &
|
|
21
|
+
NetworkConnectionOptions
|
|
22
|
+
|
|
23
|
+
type NormalizedTlsConnectionArgs = [
|
|
24
|
+
options: TlsConnectionOptions,
|
|
25
|
+
callback?: () => void,
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
export function normalizeTlsConnectArgs(
|
|
29
|
+
args: TlsConnectArgs
|
|
30
|
+
): NormalizedTlsConnectionArgs {
|
|
31
|
+
/**
|
|
32
|
+
* @note Despite incorrect type definitions, "tls.connect()" has all the
|
|
33
|
+
* options of "net.connect()" and then those specific to TLS connections,
|
|
34
|
+
* like "session" or "socket".
|
|
35
|
+
* @see https://github.com/nodejs/node/blob/bdc8131fa78089b81b74dbff467365afb6536e6a/lib/internal/tls/wrap.js#L1615
|
|
36
|
+
*/
|
|
37
|
+
const netConnectArgs = normalizeNetConnectArgs(args as NetConnectArgs)
|
|
38
|
+
const options = netConnectArgs[0] as TlsConnectionOptions
|
|
39
|
+
const callback = netConnectArgs[1]
|
|
40
|
+
|
|
41
|
+
if (args[0] !== null && typeof args[0] === 'object') {
|
|
42
|
+
Object.assign(options, args[0])
|
|
43
|
+
} else if (args[1] !== null && typeof args[1] === 'object') {
|
|
44
|
+
Object.assign(options, args[1])
|
|
45
|
+
} else if (args[2] !== null && typeof args[2] === 'object') {
|
|
46
|
+
Object.assign(options, args[2])
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return callback ? [options, callback] : [options]
|
|
50
|
+
}
|
package/src/presets/browser.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { FetchInterceptor } from '../interceptors/fetch'
|
|
2
|
-
import { XMLHttpRequestInterceptor } from '../interceptors/XMLHttpRequest'
|
|
1
|
+
import { FetchInterceptor } from '../interceptors/fetch/web'
|
|
2
|
+
import { XMLHttpRequestInterceptor } from '../interceptors/XMLHttpRequest/web'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* A browser preset for the request interception regardless
|
|
6
|
+
* of their initiator (fetch, XMLHttpRequest).
|
|
7
7
|
*/
|
|
8
8
|
export default [
|
|
9
9
|
new FetchInterceptor(),
|
package/src/presets/node.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ClientRequestInterceptor } from '../interceptors/ClientRequest'
|
|
2
|
-
import { XMLHttpRequestInterceptor } from '../interceptors/XMLHttpRequest'
|
|
3
|
-
import { FetchInterceptor } from '../interceptors/fetch'
|
|
2
|
+
import { XMLHttpRequestInterceptor } from '../interceptors/XMLHttpRequest/node'
|
|
3
|
+
import { FetchInterceptor } from '../interceptors/fetch/node'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* A Node.js preset for the request interception regardless
|
|
7
|
+
* of their initiator (http, fetch, XMLHttpRequest).
|
|
8
8
|
*/
|
|
9
9
|
export default [
|
|
10
10
|
new ClientRequestInterceptor(),
|