@mswjs/interceptors 0.20.0 → 0.21.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.
Files changed (176) hide show
  1. package/README.md +7 -7
  2. package/lib/browser/Interceptor-959f650e.d.ts +104 -0
  3. package/lib/browser/chunk-5B525MKF.mjs +2139 -0
  4. package/lib/browser/chunk-BQYA7ER5.mjs +258 -0
  5. package/lib/browser/chunk-IIY3SHU3.js +2139 -0
  6. package/lib/browser/chunk-QWL3EOEY.js +258 -0
  7. package/lib/browser/chunk-STA6QBYM.mjs +64 -0
  8. package/lib/browser/chunk-ZJOF5MEZ.js +64 -0
  9. package/lib/browser/index.d.ts +31 -0
  10. package/lib/browser/index.js +51 -0
  11. package/lib/browser/index.mjs +51 -0
  12. package/lib/browser/interceptors/XMLHttpRequest/index.d.ts +14 -0
  13. package/lib/browser/interceptors/XMLHttpRequest/index.js +657 -0
  14. package/lib/browser/interceptors/XMLHttpRequest/index.mjs +657 -0
  15. package/lib/browser/interceptors/fetch/index.d.ts +12 -0
  16. package/lib/browser/interceptors/fetch/index.js +94 -0
  17. package/lib/browser/interceptors/fetch/index.mjs +94 -0
  18. package/lib/node/BatchInterceptor-a7261b26.d.ts +21 -0
  19. package/lib/node/Interceptor-997045eb.d.ts +104 -0
  20. package/lib/{RemoteHttpInterceptor.d.ts → node/RemoteHttpInterceptor.d.ts} +17 -12
  21. package/lib/node/RemoteHttpInterceptor.js +176 -0
  22. package/lib/node/RemoteHttpInterceptor.mjs +176 -0
  23. package/lib/node/chunk-6GWWOJ23.js +29 -0
  24. package/lib/node/chunk-6V3JXLBF.js +6093 -0
  25. package/lib/node/chunk-CIN5URNI.mjs +29 -0
  26. package/lib/node/chunk-FCIAOT7W.mjs +660 -0
  27. package/lib/node/chunk-GFH37L5D.mjs +6 -0
  28. package/lib/node/chunk-HDUJCCWF.js +661 -0
  29. package/lib/node/chunk-JISWS3Y3.mjs +31 -0
  30. package/lib/node/chunk-KZJG2UW7.js +31 -0
  31. package/lib/node/chunk-NNVTJLQA.mjs +6093 -0
  32. package/lib/node/chunk-QMIXLBOU.js +291 -0
  33. package/lib/node/chunk-STA6QBYM.mjs +64 -0
  34. package/lib/node/chunk-VKKFXSTL.js +660 -0
  35. package/lib/node/chunk-VQ4DZOBB.js +6 -0
  36. package/lib/node/chunk-ZJOF5MEZ.js +64 -0
  37. package/lib/node/chunk-ZSI7MX3V.mjs +291 -0
  38. package/lib/node/chunk-ZWCZGO3W.mjs +661 -0
  39. package/lib/node/index.d.ts +14 -0
  40. package/lib/node/index.js +32 -0
  41. package/lib/node/index.mjs +32 -0
  42. package/lib/node/interceptors/ClientRequest/index.d.ts +22 -0
  43. package/lib/node/interceptors/ClientRequest/index.js +9 -0
  44. package/lib/node/interceptors/ClientRequest/index.mjs +9 -0
  45. package/lib/node/interceptors/XMLHttpRequest/index.d.ts +14 -0
  46. package/lib/node/interceptors/XMLHttpRequest/index.js +11 -0
  47. package/lib/node/interceptors/XMLHttpRequest/index.mjs +11 -0
  48. package/lib/node/interceptors/fetch/index.d.ts +12 -0
  49. package/lib/node/interceptors/fetch/index.js +96 -0
  50. package/lib/node/interceptors/fetch/index.mjs +96 -0
  51. package/package.json +58 -9
  52. package/src/interceptors/ClientRequest/utils/normalizeClientRequestArgs.ts +1 -1
  53. package/src/shims/webEncoding.ts +9 -0
  54. package/src/utils/bufferUtils.ts +1 -1
  55. package/lib/BatchInterceptor.d.ts +0 -18
  56. package/lib/BatchInterceptor.js +0 -34
  57. package/lib/BatchInterceptor.js.map +0 -1
  58. package/lib/Interceptor.d.ts +0 -50
  59. package/lib/Interceptor.js +0 -172
  60. package/lib/Interceptor.js.map +0 -1
  61. package/lib/RemoteHttpInterceptor.js +0 -158
  62. package/lib/RemoteHttpInterceptor.js.map +0 -1
  63. package/lib/glossary.d.ts +0 -7
  64. package/lib/glossary.js +0 -5
  65. package/lib/glossary.js.map +0 -1
  66. package/lib/index.d.ts +0 -5
  67. package/lib/index.js +0 -23
  68. package/lib/index.js.map +0 -1
  69. package/lib/interceptors/ClientRequest/NodeClientRequest.d.ts +0 -46
  70. package/lib/interceptors/ClientRequest/NodeClientRequest.js +0 -325
  71. package/lib/interceptors/ClientRequest/NodeClientRequest.js.map +0 -1
  72. package/lib/interceptors/ClientRequest/http.get.d.ts +0 -4
  73. package/lib/interceptors/ClientRequest/http.get.js +0 -19
  74. package/lib/interceptors/ClientRequest/http.get.js.map +0 -1
  75. package/lib/interceptors/ClientRequest/http.request.d.ts +0 -4
  76. package/lib/interceptors/ClientRequest/http.request.js +0 -16
  77. package/lib/interceptors/ClientRequest/http.request.js.map +0 -1
  78. package/lib/interceptors/ClientRequest/index.d.ts +0 -19
  79. package/lib/interceptors/ClientRequest/index.js +0 -50
  80. package/lib/interceptors/ClientRequest/index.js.map +0 -1
  81. package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.d.ts +0 -10
  82. package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.js +0 -60
  83. package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.js.map +0 -1
  84. package/lib/interceptors/ClientRequest/utils/createRequest.d.ts +0 -6
  85. package/lib/interceptors/ClientRequest/utils/createRequest.js +0 -30
  86. package/lib/interceptors/ClientRequest/utils/createRequest.js.map +0 -1
  87. package/lib/interceptors/ClientRequest/utils/createResponse.d.ts +0 -8
  88. package/lib/interceptors/ClientRequest/utils/createResponse.js +0 -24
  89. package/lib/interceptors/ClientRequest/utils/createResponse.js.map +0 -1
  90. package/lib/interceptors/ClientRequest/utils/getIncomingMessageBody.d.ts +0 -3
  91. package/lib/interceptors/ClientRequest/utils/getIncomingMessageBody.js +0 -57
  92. package/lib/interceptors/ClientRequest/utils/getIncomingMessageBody.js.map +0 -1
  93. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestArgs.d.ts +0 -17
  94. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestArgs.js +0 -151
  95. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestArgs.js.map +0 -1
  96. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.d.ts +0 -15
  97. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.js +0 -33
  98. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.js.map +0 -1
  99. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.d.ts +0 -13
  100. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.js +0 -20
  101. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.js.map +0 -1
  102. package/lib/interceptors/XMLHttpRequest/XMLHttpRequestController.d.ts +0 -44
  103. package/lib/interceptors/XMLHttpRequest/XMLHttpRequestController.js +0 -413
  104. package/lib/interceptors/XMLHttpRequest/XMLHttpRequestController.js.map +0 -1
  105. package/lib/interceptors/XMLHttpRequest/XMLHttpRequestProxy.d.ts +0 -20
  106. package/lib/interceptors/XMLHttpRequest/XMLHttpRequestProxy.js +0 -75
  107. package/lib/interceptors/XMLHttpRequest/XMLHttpRequestProxy.js.map +0 -1
  108. package/lib/interceptors/XMLHttpRequest/index.d.ts +0 -12
  109. package/lib/interceptors/XMLHttpRequest/index.js +0 -41
  110. package/lib/interceptors/XMLHttpRequest/index.js.map +0 -1
  111. package/lib/interceptors/XMLHttpRequest/polyfills/EventPolyfill.d.ts +0 -31
  112. package/lib/interceptors/XMLHttpRequest/polyfills/EventPolyfill.js +0 -44
  113. package/lib/interceptors/XMLHttpRequest/polyfills/EventPolyfill.js.map +0 -1
  114. package/lib/interceptors/XMLHttpRequest/polyfills/ProgressEventPolyfill.d.ts +0 -8
  115. package/lib/interceptors/XMLHttpRequest/polyfills/ProgressEventPolyfill.js +0 -15
  116. package/lib/interceptors/XMLHttpRequest/polyfills/ProgressEventPolyfill.js.map +0 -1
  117. package/lib/interceptors/XMLHttpRequest/utils/concatArrayBuffer.d.ts +0 -4
  118. package/lib/interceptors/XMLHttpRequest/utils/concatArrayBuffer.js +0 -14
  119. package/lib/interceptors/XMLHttpRequest/utils/concatArrayBuffer.js.map +0 -1
  120. package/lib/interceptors/XMLHttpRequest/utils/createEvent.d.ts +0 -2
  121. package/lib/interceptors/XMLHttpRequest/utils/createEvent.js +0 -37
  122. package/lib/interceptors/XMLHttpRequest/utils/createEvent.js.map +0 -1
  123. package/lib/interceptors/XMLHttpRequest/utils/createResponse.d.ts +0 -2
  124. package/lib/interceptors/XMLHttpRequest/utils/createResponse.js +0 -14
  125. package/lib/interceptors/XMLHttpRequest/utils/createResponse.js.map +0 -1
  126. package/lib/interceptors/XMLHttpRequest/utils/isDomParserSupportedType.d.ts +0 -1
  127. package/lib/interceptors/XMLHttpRequest/utils/isDomParserSupportedType.js +0 -17
  128. package/lib/interceptors/XMLHttpRequest/utils/isDomParserSupportedType.js.map +0 -1
  129. package/lib/interceptors/fetch/index.d.ts +0 -8
  130. package/lib/interceptors/fetch/index.js +0 -81
  131. package/lib/interceptors/fetch/index.js.map +0 -1
  132. package/lib/presets/browser.d.ts +0 -8
  133. package/lib/presets/browser.js +0 -10
  134. package/lib/presets/browser.js.map +0 -1
  135. package/lib/presets/node.d.ts +0 -8
  136. package/lib/presets/node.js +0 -10
  137. package/lib/presets/node.js.map +0 -1
  138. package/lib/utils/AsyncEventEmitter.d.ts +0 -33
  139. package/lib/utils/AsyncEventEmitter.js +0 -148
  140. package/lib/utils/AsyncEventEmitter.js.map +0 -1
  141. package/lib/utils/bufferUtils.d.ts +0 -8
  142. package/lib/utils/bufferUtils.js +0 -24
  143. package/lib/utils/bufferUtils.js.map +0 -1
  144. package/lib/utils/cloneObject.d.ts +0 -1
  145. package/lib/utils/cloneObject.js +0 -28
  146. package/lib/utils/cloneObject.js.map +0 -1
  147. package/lib/utils/createLazyCallback.d.ts +0 -11
  148. package/lib/utils/createLazyCallback.js +0 -40
  149. package/lib/utils/createLazyCallback.js.map +0 -1
  150. package/lib/utils/createProxy.d.ts +0 -8
  151. package/lib/utils/createProxy.js +0 -45
  152. package/lib/utils/createProxy.js.map +0 -1
  153. package/lib/utils/getCleanUrl.d.ts +0 -4
  154. package/lib/utils/getCleanUrl.js +0 -11
  155. package/lib/utils/getCleanUrl.js.map +0 -1
  156. package/lib/utils/getRequestOptionsByUrl.d.ts +0 -8
  157. package/lib/utils/getRequestOptionsByUrl.js +0 -28
  158. package/lib/utils/getRequestOptionsByUrl.js.map +0 -1
  159. package/lib/utils/getUrlByRequestOptions.d.ts +0 -11
  160. package/lib/utils/getUrlByRequestOptions.js +0 -78
  161. package/lib/utils/getUrlByRequestOptions.js.map +0 -1
  162. package/lib/utils/isObject.d.ts +0 -4
  163. package/lib/utils/isObject.js +0 -11
  164. package/lib/utils/isObject.js.map +0 -1
  165. package/lib/utils/nextTick.d.ts +0 -2
  166. package/lib/utils/nextTick.js +0 -16
  167. package/lib/utils/nextTick.js.map +0 -1
  168. package/lib/utils/parseJson.d.ts +0 -5
  169. package/lib/utils/parseJson.js +0 -18
  170. package/lib/utils/parseJson.js.map +0 -1
  171. package/lib/utils/toInteractiveRequest.d.ts +0 -7
  172. package/lib/utils/toInteractiveRequest.js +0 -20
  173. package/lib/utils/toInteractiveRequest.js.map +0 -1
  174. package/lib/utils/uuid.d.ts +0 -1
  175. package/lib/utils/uuid.js +0 -12
  176. package/lib/utils/uuid.js.map +0 -1
@@ -1,57 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.getIncomingMessageBody = void 0;
23
- const debug_1 = require("debug");
24
- const stream_1 = require("stream");
25
- const zlib = __importStar(require("zlib"));
26
- const log = (0, debug_1.debug)('http getIncomingMessageBody');
27
- function getIncomingMessageBody(response) {
28
- return new Promise((resolve, reject) => {
29
- log('cloning the original response...');
30
- // Pipe the original response to support non-clone
31
- // "response" input. No need to clone the response,
32
- // as we always have access to the full "response" input,
33
- // either a clone or an original one (in tests).
34
- const responseClone = response.pipe(new stream_1.PassThrough());
35
- const stream = response.headers['content-encoding'] === 'gzip'
36
- ? responseClone.pipe(zlib.createGunzip())
37
- : responseClone;
38
- const encoding = response.readableEncoding || 'utf8';
39
- stream.setEncoding(encoding);
40
- log('using encoding:', encoding);
41
- let body = '';
42
- stream.on('data', (responseBody) => {
43
- log('response body read:', responseBody);
44
- body += responseBody;
45
- });
46
- stream.once('end', () => {
47
- log('response body end');
48
- resolve(body);
49
- });
50
- stream.once('error', (error) => {
51
- log('error while reading response body:', error);
52
- reject(error);
53
- });
54
- });
55
- }
56
- exports.getIncomingMessageBody = getIncomingMessageBody;
57
- //# sourceMappingURL=getIncomingMessageBody.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getIncomingMessageBody.js","sourceRoot":"","sources":["../../../../src/interceptors/ClientRequest/utils/getIncomingMessageBody.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,iCAA6B;AAE7B,mCAAoC;AACpC,2CAA4B;AAE5B,MAAM,GAAG,GAAG,IAAA,aAAK,EAAC,6BAA6B,CAAC,CAAA;AAEhD,SAAgB,sBAAsB,CACpC,QAAyB;IAEzB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,GAAG,CAAC,kCAAkC,CAAC,CAAA;QAEvC,kDAAkD;QAClD,mDAAmD;QACnD,yDAAyD;QACzD,gDAAgD;QAChD,MAAM,aAAa,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,oBAAW,EAAE,CAAC,CAAA;QACtD,MAAM,MAAM,GACV,QAAQ,CAAC,OAAO,CAAC,kBAAkB,CAAC,KAAK,MAAM;YAC7C,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACzC,CAAC,CAAC,aAAa,CAAA;QAEnB,MAAM,QAAQ,GAAG,QAAQ,CAAC,gBAAgB,IAAI,MAAM,CAAA;QACpD,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;QAC5B,GAAG,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAA;QAEhC,IAAI,IAAI,GAAG,EAAE,CAAA;QAEb,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,YAAY,EAAE,EAAE;YACjC,GAAG,CAAC,qBAAqB,EAAE,YAAY,CAAC,CAAA;YACxC,IAAI,IAAI,YAAY,CAAA;QACtB,CAAC,CAAC,CAAA;QAEF,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE;YACtB,GAAG,CAAC,mBAAmB,CAAC,CAAA;YACxB,OAAO,CAAC,IAAI,CAAC,CAAA;QACf,CAAC,CAAC,CAAA;QAEF,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YAC7B,GAAG,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAA;YAChD,MAAM,CAAC,KAAK,CAAC,CAAA;QACf,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC;AArCD,wDAqCC"}
@@ -1,17 +0,0 @@
1
- /// <reference types="node" />
2
- import { IncomingMessage } from 'http';
3
- import { RequestOptions } from 'https';
4
- import { Url as LegacyURL } from 'url';
5
- import { ResolvedRequestOptions } from '../../../utils/getUrlByRequestOptions';
6
- export declare type HttpRequestCallback = (response: IncomingMessage) => void;
7
- export declare type ClientRequestArgs = [string | URL | LegacyURL, HttpRequestCallback?] | [string | URL | LegacyURL, RequestOptions, HttpRequestCallback?] | [RequestOptions, HttpRequestCallback?];
8
- export declare type NormalizedClientRequestArgs = [
9
- url: URL,
10
- options: ResolvedRequestOptions,
11
- callback?: HttpRequestCallback
12
- ];
13
- /**
14
- * Normalizes parameters given to a `http.request` call
15
- * so it always has a `URL` and `RequestOptions`.
16
- */
17
- export declare function normalizeClientRequestArgs(defaultProtocol: string, ...args: ClientRequestArgs): NormalizedClientRequestArgs;
@@ -1,151 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeClientRequestArgs = void 0;
4
- const debug_1 = require("debug");
5
- const http_1 = require("http");
6
- const https_1 = require("https");
7
- const getRequestOptionsByUrl_1 = require("../../../utils/getRequestOptionsByUrl");
8
- const getUrlByRequestOptions_1 = require("../../../utils/getUrlByRequestOptions");
9
- const cloneObject_1 = require("../../../utils/cloneObject");
10
- const isObject_1 = require("../../../utils/isObject");
11
- const log = (0, debug_1.debug)('http normalizeClientRequestArgs');
12
- function resolveRequestOptions(args, url) {
13
- // Calling `fetch` provides only URL to `ClientRequest`
14
- // without any `RequestOptions` or callback.
15
- if (typeof args[1] === 'undefined' || typeof args[1] === 'function') {
16
- log('request options not provided, deriving from the url', url);
17
- return (0, getRequestOptionsByUrl_1.getRequestOptionsByUrl)(url);
18
- }
19
- if (args[1]) {
20
- log('has custom RequestOptions!', args[1]);
21
- const requestOptionsFromUrl = (0, getRequestOptionsByUrl_1.getRequestOptionsByUrl)(url);
22
- log('derived RequestOptions from the URL:', requestOptionsFromUrl);
23
- /**
24
- * Clone the request options to lock their state
25
- * at the moment they are provided to `ClientRequest`.
26
- * @see https://github.com/mswjs/interceptors/issues/86
27
- */
28
- log('cloning RequestOptions...');
29
- const clonedRequestOptions = (0, cloneObject_1.cloneObject)(args[1]);
30
- log('successfully cloned RequestOptions!', clonedRequestOptions);
31
- return Object.assign(Object.assign({}, requestOptionsFromUrl), clonedRequestOptions);
32
- }
33
- log('using an empty object as request options');
34
- return {};
35
- }
36
- function resolveCallback(args) {
37
- return typeof args[1] === 'function' ? args[1] : args[2];
38
- }
39
- /**
40
- * Normalizes parameters given to a `http.request` call
41
- * so it always has a `URL` and `RequestOptions`.
42
- */
43
- function normalizeClientRequestArgs(defaultProtocol, ...args) {
44
- let url;
45
- let options;
46
- let callback;
47
- log('arguments', args);
48
- log('using default protocol:', defaultProtocol);
49
- // Convert a url string into a URL instance
50
- // and derive request options from it.
51
- if (typeof args[0] === 'string') {
52
- log('first argument is a location string:', args[0]);
53
- url = new URL(args[0]);
54
- log('created a url:', url);
55
- const requestOptionsFromUrl = (0, getRequestOptionsByUrl_1.getRequestOptionsByUrl)(url);
56
- log('request options from url:', requestOptionsFromUrl);
57
- options = resolveRequestOptions(args, url);
58
- log('resolved request options:', options);
59
- callback = resolveCallback(args);
60
- }
61
- // Handle a given URL instance as-is
62
- // and derive request options from it.
63
- else if (args[0] instanceof URL) {
64
- url = args[0];
65
- log('first argument is a URL:', url);
66
- options = resolveRequestOptions(args, url);
67
- log('derived request options:', options);
68
- callback = resolveCallback(args);
69
- }
70
- // Handle a legacy URL instance and re-normalize from either a RequestOptions object
71
- // or a WHATWG URL.
72
- else if ('hash' in args[0] && !('method' in args[0])) {
73
- const [legacyUrl] = args;
74
- log('first argument is a legacy URL:', legacyUrl);
75
- if (legacyUrl.hostname === null) {
76
- /**
77
- * We are dealing with a relative url, so use the path as an "option" and
78
- * merge in any existing options, giving priority to exising options -- i.e. a path in any
79
- * existing options will take precedence over the one contained in the url. This is consistent
80
- * with the behaviour in ClientRequest.
81
- * @see https://github.com/nodejs/node/blob/d84f1312915fe45fe0febe888db692c74894c382/lib/_http_client.js#L122
82
- */
83
- log('given legacy URL is relative (no hostname)');
84
- return (0, isObject_1.isObject)(args[1])
85
- ? normalizeClientRequestArgs(defaultProtocol, Object.assign({ path: legacyUrl.path }, args[1]), args[2])
86
- : normalizeClientRequestArgs(defaultProtocol, { path: legacyUrl.path }, args[1]);
87
- }
88
- log('given legacy url is absolute');
89
- // We are dealing with an absolute URL, so convert to WHATWG and try again.
90
- const resolvedUrl = new URL(legacyUrl.href);
91
- return args[1] === undefined
92
- ? normalizeClientRequestArgs(defaultProtocol, resolvedUrl)
93
- : typeof args[1] === 'function'
94
- ? normalizeClientRequestArgs(defaultProtocol, resolvedUrl, args[1])
95
- : normalizeClientRequestArgs(defaultProtocol, resolvedUrl, args[1], args[2]);
96
- }
97
- // Handle a given "RequestOptions" object as-is
98
- // and derive the URL instance from it.
99
- else if ((0, isObject_1.isObject)(args[0])) {
100
- options = args[0];
101
- log('first argument is RequestOptions:', options);
102
- // When handling a "RequestOptions" object without an explicit "protocol",
103
- // infer the protocol from the request issuing module (http/https).
104
- options.protocol = options.protocol || defaultProtocol;
105
- log('normalized request options:', options);
106
- url = (0, getUrlByRequestOptions_1.getUrlByRequestOptions)(options);
107
- log('created a URL from RequestOptions:', url.href);
108
- callback = resolveCallback(args);
109
- }
110
- else {
111
- throw new Error(`Failed to construct ClientRequest with these parameters: ${args}`);
112
- }
113
- options.protocol = options.protocol || url.protocol;
114
- options.method = options.method || 'GET';
115
- /**
116
- * Infer a fallback agent from the URL protocol.
117
- * The interception is done on the "ClientRequest" level ("NodeClientRequest")
118
- * and it may miss the correct agent. Always align the agent
119
- * with the URL protocol, if not provided.
120
- *
121
- * @note Respect the "agent: false" value.
122
- */
123
- if (typeof options.agent === 'undefined') {
124
- const agent = options.protocol === 'https:'
125
- ? new https_1.Agent({
126
- rejectUnauthorized: options.rejectUnauthorized,
127
- })
128
- : new http_1.Agent();
129
- options.agent = agent;
130
- log('resolved fallback agent:', agent);
131
- }
132
- /**
133
- * Ensure that the default Agent is always set.
134
- * This prevents the protocol mismatch for requests with { agent: false },
135
- * where the global Agent is inferred.
136
- * @see https://github.com/mswjs/msw/issues/1150
137
- * @see https://github.com/nodejs/node/blob/418ff70b810f0e7112d48baaa72932a56cfa213b/lib/_http_client.js#L130
138
- * @see https://github.com/nodejs/node/blob/418ff70b810f0e7112d48baaa72932a56cfa213b/lib/_http_client.js#L157-L159
139
- */
140
- if (!options._defaultAgent) {
141
- log('has no default agent, setting the default agent for "%s"', options.protocol);
142
- options._defaultAgent =
143
- options.protocol === 'https:' ? https_1.globalAgent : http_1.globalAgent;
144
- }
145
- log('successfully resolved url:', url.href);
146
- log('successfully resolved options:', options);
147
- log('successfully resolved callback:', callback);
148
- return [url, options, callback];
149
- }
150
- exports.normalizeClientRequestArgs = normalizeClientRequestArgs;
151
- //# sourceMappingURL=normalizeClientRequestArgs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"normalizeClientRequestArgs.js","sourceRoot":"","sources":["../../../../src/interceptors/ClientRequest/utils/normalizeClientRequestArgs.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAC7B,+BAIa;AACb,iCAIc;AAEd,kFAA8E;AAC9E,kFAG8C;AAC9C,4DAAwD;AACxD,sDAAkD;AAElD,MAAM,GAAG,GAAG,IAAA,aAAK,EAAC,iCAAiC,CAAC,CAAA;AASpD,SAAS,qBAAqB,CAC5B,IAAuB,EACvB,GAAQ;IAER,uDAAuD;IACvD,4CAA4C;IAC5C,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,WAAW,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,UAAU,EAAE;QACnE,GAAG,CAAC,qDAAqD,EAAE,GAAG,CAAC,CAAA;QAC/D,OAAO,IAAA,+CAAsB,EAAC,GAAG,CAAC,CAAA;KACnC;IAED,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE;QACX,GAAG,CAAC,4BAA4B,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;QAC1C,MAAM,qBAAqB,GAAG,IAAA,+CAAsB,EAAC,GAAG,CAAC,CAAA;QAEzD,GAAG,CAAC,sC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,KAAK,WAAW,EAAE;QACxC,MAAM,KAAK,GACT,OAAO,CAAC,QAAQ,KAAK,QAAQ;YAC3B,CAAC,CAAC,IAAI,aAAU,CAAC;gBACb,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;aAC/C,CAAC;YACJ,CAAC,CAAC,IAAI,YAAS,EAAE,CAAA;QAErB,OAAO,CAAC,KAAK,GAAG,KAAK,CAAA;QACrB,GAAG,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAA;KACvC;IAED;;;;;;;OAOG;IACH,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE;QAC1B,GAAG,CACD,0DAA0D,EAC1D,OAAO,CAAC,QAAQ,CACjB,CAAA;QAED,OAAO,CAAC,aAAa;YACnB,OAAO,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,mBAAgB,CAAC,CAAC,CAAC,kBAAe,CAAA;KACrE;IAED,GAAG,CAAC,4BAA4B,EAAE,GAAG,CAAC,IAAI,CAAC,CAAA;IAC3C,GAAG,CAAC,gCAAgC,EAAE,OAAO,CAAC,CAAA;IAC9C,GAAG,CAAC,iCAAiC,EAAE,QAAQ,CAAC,CAAA;IAEhD,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;AACjC,CAAC;AAtJD,gEAsJC"}
@@ -1,15 +0,0 @@
1
- /// <reference types="node" />
2
- export declare type ClientRequestEndChunk = string | Buffer;
3
- export declare type ClientRequestEndCallback = () => void;
4
- declare type HttpRequestEndArgs = [] | [ClientRequestEndCallback] | [ClientRequestEndChunk, ClientRequestEndCallback?] | [ClientRequestEndChunk, BufferEncoding, ClientRequestEndCallback?];
5
- declare type NormalizedHttpRequestEndParams = [
6
- ClientRequestEndChunk | null,
7
- BufferEncoding | null,
8
- ClientRequestEndCallback | null
9
- ];
10
- /**
11
- * Normalizes a list of arguments given to the `ClientRequest.end()`
12
- * method to always include `chunk`, `encoding`, and `callback`.
13
- */
14
- export declare function normalizeClientRequestEndArgs(...args: HttpRequestEndArgs): NormalizedHttpRequestEndParams;
15
- export {};
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeClientRequestEndArgs = void 0;
4
- const debug = require('debug')('http normalizeClientRequestEndArgs');
5
- /**
6
- * Normalizes a list of arguments given to the `ClientRequest.end()`
7
- * method to always include `chunk`, `encoding`, and `callback`.
8
- */
9
- function normalizeClientRequestEndArgs(...args) {
10
- debug('arguments', args);
11
- const normalizedArgs = new Array(3)
12
- .fill(null)
13
- .map((value, index) => args[index] || value);
14
- normalizedArgs.sort((a, b) => {
15
- // If first element is a function, move it rightwards.
16
- if (typeof a === 'function') {
17
- return 1;
18
- }
19
- // If second element is a function, move the first leftwards.
20
- if (typeof b === 'function') {
21
- return -1;
22
- }
23
- // If both elements are strings, preserve their original index.
24
- if (typeof a === 'string' && typeof b === 'string') {
25
- return normalizedArgs.indexOf(a) - normalizedArgs.indexOf(b);
26
- }
27
- return 0;
28
- });
29
- debug('normalized args', normalizedArgs);
30
- return normalizedArgs;
31
- }
32
- exports.normalizeClientRequestEndArgs = normalizeClientRequestEndArgs;
33
- //# sourceMappingURL=normalizeClientRequestEndArgs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"normalizeClientRequestEndArgs.js","sourceRoot":"","sources":["../../../../src/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.ts"],"names":[],"mappings":";;;AAAA,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,oCAAoC,CAAC,CAAA;AAiBpE;;;GAGG;AACH,SAAgB,6BAA6B,CAC3C,GAAG,IAAwB;IAE3B,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;IACxB,MAAM,cAAc,GAAG,IAAI,KAAK,CAAC,CAAC,CAAC;SAChC,IAAI,CAAC,IAAI,CAAC;SACV,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,CAAA;IAE9C,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAC3B,sDAAsD;QACtD,IAAI,OAAO,CAAC,KAAK,UAAU,EAAE;YAC3B,OAAO,CAAC,CAAA;SACT;QAED,6DAA6D;QAC7D,IAAI,OAAO,CAAC,KAAK,UAAU,EAAE;YAC3B,OAAO,CAAC,CAAC,CAAA;SACV;QAED,+DAA+D;QAC/D,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE;YAClD,OAAO,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;SAC7D;QAED,OAAO,CAAC,CAAA;IACV,CAAC,CAAC,CAAA;IAEF,KAAK,CAAC,iBAAiB,EAAE,cAAc,CAAC,CAAA;IACxC,OAAO,cAAgD,CAAA;AACzD,CAAC;AA7BD,sEA6BC"}
@@ -1,13 +0,0 @@
1
- /// <reference types="node" />
2
- export declare type ClientRequestWriteCallback = (error?: Error | null) => void;
3
- export declare type ClientRequestWriteArgs = [
4
- chunk: string | Buffer,
5
- encoding?: BufferEncoding | ClientRequestWriteCallback,
6
- callback?: ClientRequestWriteCallback
7
- ];
8
- export declare type NormalizedClientRequestWriteArgs = [
9
- chunk: string | Buffer,
10
- encoding?: BufferEncoding,
11
- callback?: ClientRequestWriteCallback
12
- ];
13
- export declare function normalizeClientRequestWriteArgs(args: ClientRequestWriteArgs): NormalizedClientRequestWriteArgs;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeClientRequestWriteArgs = void 0;
4
- const debug_1 = require("debug");
5
- const log = (0, debug_1.debug)('http normalizeWriteArgs');
6
- function normalizeClientRequestWriteArgs(args) {
7
- log('normalizing ClientRequest.write arguments...', args);
8
- const chunk = args[0];
9
- const encoding = typeof args[1] === 'string' ? args[1] : undefined;
10
- const callback = typeof args[1] === 'function' ? args[1] : args[2];
11
- const writeArgs = [
12
- chunk,
13
- encoding,
14
- callback,
15
- ];
16
- log('successfully normalized ClientRequest.write arguments:', writeArgs);
17
- return writeArgs;
18
- }
19
- exports.normalizeClientRequestWriteArgs = normalizeClientRequestWriteArgs;
20
- //# sourceMappingURL=normalizeClientRequestWriteArgs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"normalizeClientRequestWriteArgs.js","sourceRoot":"","sources":["../../../../src/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAE7B,MAAM,GAAG,GAAG,IAAA,aAAK,EAAC,yBAAyB,CAAC,CAAA;AAe5C,SAAgB,+BAA+B,CAC7C,IAA4B;IAE5B,GAAG,CAAC,8CAA8C,EAAE,IAAI,CAAC,CAAA;IAEzD,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;IACrB,MAAM,QAAQ,GACZ,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAE,IAAI,CAAC,CAAC,CAAoB,CAAC,CAAC,CAAC,SAAS,CAAA;IACvE,MAAM,QAAQ,GAAG,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAElE,MAAM,SAAS,GAAqC;QAClD,KAAK;QACL,QAAQ;QACR,QAAQ;KACT,CAAA;IACD,GAAG,CAAC,wDAAwD,EAAE,SAAS,CAAC,CAAA;IAExE,OAAO,SAAS,CAAA;AAClB,CAAC;AAlBD,0EAkBC"}
@@ -1,44 +0,0 @@
1
- import type { Debugger } from 'debug';
2
- import { Request } from '@remix-run/web-fetch';
3
- /**
4
- * An `XMLHttpRequest` instance controller that allows us
5
- * to handle any given request instance (e.g. responding to it).
6
- */
7
- export declare class XMLHttpRequestController {
8
- readonly initialRequest: XMLHttpRequest;
9
- log: Debugger;
10
- request: XMLHttpRequest;
11
- requestId?: string;
12
- onRequest?: (this: XMLHttpRequestController, request: Request, requestId: string) => Promise<void>;
13
- onResponse?: (this: XMLHttpRequestController, response: Response, request: Request, requestId: string) => void;
14
- private method;
15
- private url;
16
- private requestHeaders;
17
- private requestBody?;
18
- private responseBuffer;
19
- private events;
20
- constructor(initialRequest: XMLHttpRequest, log: Debugger);
21
- private registerEvent;
22
- /**
23
- * Responds to the current request with the given
24
- * Fetch API `Response` instance.
25
- */
26
- respondWith(response: Response): void;
27
- private responseBufferToText;
28
- get response(): unknown;
29
- get responseText(): string;
30
- get responseXML(): Document | null;
31
- errorWith(error: Error): void;
32
- /**
33
- * Transitions this request's `readyState` to the given one.
34
- */
35
- private setReadyState;
36
- /**
37
- * Triggers given event on the `XMLHttpRequest` instance.
38
- */
39
- private trigger;
40
- /**
41
- * Converts this `XMLHttpRequest` instance into a Fetch API `Request` instance.
42
- */
43
- toFetchApiRequest(): Request;
44
- }