@mswjs/interceptors 0.19.4 → 0.20.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/lib/BatchInterceptor.d.ts +5 -5
- package/lib/BatchInterceptor.js +14 -59
- package/lib/BatchInterceptor.js.map +1 -1
- package/lib/Interceptor.d.ts +7 -6
- package/lib/Interceptor.js +39 -64
- package/lib/Interceptor.js.map +1 -1
- package/lib/RemoteHttpInterceptor.js +115 -209
- package/lib/RemoteHttpInterceptor.js.map +1 -1
- package/lib/glossary.d.ts +2 -2
- package/lib/interceptors/ClientRequest/NodeClientRequest.js +141 -278
- package/lib/interceptors/ClientRequest/NodeClientRequest.js.map +1 -1
- package/lib/interceptors/ClientRequest/http.get.js +5 -34
- package/lib/interceptors/ClientRequest/http.get.js.map +1 -1
- package/lib/interceptors/ClientRequest/http.request.js +6 -35
- package/lib/interceptors/ClientRequest/http.request.js.map +1 -1
- package/lib/interceptors/ClientRequest/index.js +22 -82
- package/lib/interceptors/ClientRequest/index.js.map +1 -1
- package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.js +18 -62
- package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.js.map +1 -1
- package/lib/interceptors/ClientRequest/utils/createRequest.js +10 -32
- package/lib/interceptors/ClientRequest/utils/createRequest.js.map +1 -1
- package/lib/interceptors/ClientRequest/utils/createResponse.js +6 -6
- package/lib/interceptors/ClientRequest/utils/createResponse.js.map +1 -1
- package/lib/interceptors/ClientRequest/utils/getIncomingMessageBody.js +12 -12
- package/lib/interceptors/ClientRequest/utils/getIncomingMessageBody.js.map +1 -1
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestArgs.js +21 -52
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestArgs.js.map +1 -1
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.js +5 -9
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.js.map +1 -1
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.js +6 -6
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.js.map +1 -1
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestController.d.ts +44 -0
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestController.js +413 -0
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestController.js.map +1 -0
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestProxy.d.ts +20 -0
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestProxy.js +75 -0
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestProxy.js.map +1 -0
- package/lib/interceptors/XMLHttpRequest/index.js +23 -42
- package/lib/interceptors/XMLHttpRequest/index.js.map +1 -1
- package/lib/interceptors/XMLHttpRequest/polyfills/EventPolyfill.js +11 -12
- package/lib/interceptors/XMLHttpRequest/polyfills/EventPolyfill.js.map +1 -1
- package/lib/interceptors/XMLHttpRequest/polyfills/ProgressEventPolyfill.js +9 -27
- package/lib/interceptors/XMLHttpRequest/polyfills/ProgressEventPolyfill.js.map +1 -1
- package/lib/interceptors/XMLHttpRequest/utils/concatArrayBuffer.js +1 -1
- package/lib/interceptors/XMLHttpRequest/utils/concatArrayBuffer.js.map +1 -1
- package/lib/interceptors/XMLHttpRequest/utils/createEvent.js +7 -7
- package/lib/interceptors/XMLHttpRequest/utils/createEvent.js.map +1 -1
- package/lib/interceptors/XMLHttpRequest/utils/createResponse.js +2 -2
- package/lib/interceptors/XMLHttpRequest/utils/createResponse.js.map +1 -1
- package/lib/interceptors/XMLHttpRequest/utils/isDomParserSupportedType.js +2 -2
- package/lib/interceptors/XMLHttpRequest/utils/isDomParserSupportedType.js.map +1 -1
- package/lib/interceptors/fetch/index.js +52 -125
- package/lib/interceptors/fetch/index.js.map +1 -1
- package/lib/presets/browser.js +2 -2
- package/lib/presets/browser.js.map +1 -1
- package/lib/presets/node.js +2 -2
- package/lib/presets/node.js.map +1 -1
- package/lib/utils/AsyncEventEmitter.d.ts +9 -8
- package/lib/utils/AsyncEventEmitter.js +84 -190
- package/lib/utils/AsyncEventEmitter.js.map +1 -1
- package/lib/utils/bufferUtils.js +3 -3
- package/lib/utils/bufferUtils.js.map +1 -1
- package/lib/utils/cloneObject.js +2 -19
- package/lib/utils/cloneObject.js.map +1 -1
- package/lib/utils/createLazyCallback.js +14 -49
- package/lib/utils/createLazyCallback.js.map +1 -1
- package/lib/utils/createProxy.d.ts +8 -0
- package/lib/utils/createProxy.js +45 -0
- package/lib/utils/createProxy.js.map +1 -0
- package/lib/utils/getCleanUrl.js +1 -2
- package/lib/utils/getCleanUrl.js.map +1 -1
- package/lib/utils/getRequestOptionsByUrl.js +3 -3
- package/lib/utils/getRequestOptionsByUrl.js.map +1 -1
- package/lib/utils/getUrlByRequestOptions.js +23 -39
- package/lib/utils/getUrlByRequestOptions.js.map +1 -1
- package/lib/utils/nextTick.js +2 -2
- package/lib/utils/nextTick.js.map +1 -1
- package/lib/utils/parseJson.js +1 -1
- package/lib/utils/parseJson.js.map +1 -1
- package/lib/utils/toInteractiveRequest.js +3 -3
- package/lib/utils/toInteractiveRequest.js.map +1 -1
- package/lib/utils/uuid.js +2 -2
- package/lib/utils/uuid.js.map +1 -1
- package/package.json +2 -2
- package/src/BatchInterceptor.test.ts +2 -2
- package/src/BatchInterceptor.ts +14 -13
- package/src/Interceptor.ts +12 -11
- package/src/glossary.ts +2 -6
- package/src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts +578 -0
- package/src/interceptors/XMLHttpRequest/XMLHttpRequestProxy.ts +111 -0
- package/src/interceptors/XMLHttpRequest/index.ts +12 -13
- package/src/utils/AsyncEventEmitter.test.ts +6 -6
- package/src/utils/AsyncEventEmitter.ts +60 -50
- package/src/utils/createProxy.ts +78 -0
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestOverride.d.ts +0 -93
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestOverride.js +0 -567
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestOverride.js.map +0 -1
- package/src/interceptors/XMLHttpRequest/XMLHttpRequestOverride.ts +0 -684
|
@@ -1,41 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
3
|
exports.get = void 0;
|
|
29
|
-
|
|
30
|
-
|
|
4
|
+
const NodeClientRequest_1 = require("./NodeClientRequest");
|
|
5
|
+
const normalizeClientRequestArgs_1 = require("./utils/normalizeClientRequestArgs");
|
|
31
6
|
function get(protocol, options) {
|
|
32
|
-
return
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
args[_i] = arguments[_i];
|
|
36
|
-
}
|
|
37
|
-
var clientRequestArgs = normalizeClientRequestArgs_1.normalizeClientRequestArgs.apply(void 0, __spreadArray([protocol + ":"], __read(args), false));
|
|
38
|
-
var request = new NodeClientRequest_1.NodeClientRequest(clientRequestArgs, options);
|
|
7
|
+
return (...args) => {
|
|
8
|
+
const clientRequestArgs = (0, normalizeClientRequestArgs_1.normalizeClientRequestArgs)(`${protocol}:`, ...args);
|
|
9
|
+
const request = new NodeClientRequest_1.NodeClientRequest(clientRequestArgs, options);
|
|
39
10
|
/**
|
|
40
11
|
* @note https://nodejs.org/api/http.html#httpgetoptions-callback
|
|
41
12
|
* "http.get" sets the method to "GET" and calls "req.end()" automatically.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.get.js","sourceRoot":"","sources":["../../../src/interceptors/ClientRequest/http.get.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http.get.js","sourceRoot":"","sources":["../../../src/interceptors/ClientRequest/http.get.ts"],"names":[],"mappings":";;;AACA,2DAI4B;AAC5B,mFAG2C;AAE3C,SAAgB,GAAG,CAAC,QAAkB,EAAE,OAA0B;IAChE,OAAO,CAAC,GAAG,IAAuB,EAAiB,EAAE;QACnD,MAAM,iBAAiB,GAAG,IAAA,uDAA0B,EAClD,GAAG,QAAQ,GAAG,EACd,GAAG,IAAI,CACR,CAAA;QACD,MAAM,OAAO,GAAG,IAAI,qCAAiB,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAA;QAEjE;;;WAGG;QACH,OAAO,CAAC,GAAG,EAAE,CAAA;QAEb,OAAO,OAAO,CAAA;IAChB,CAAC,CAAA;AACH,CAAC;AAhBD,kBAgBC"}
|
|
@@ -1,43 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
3
|
exports.request = void 0;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
4
|
+
const debug_1 = require("debug");
|
|
5
|
+
const NodeClientRequest_1 = require("./NodeClientRequest");
|
|
6
|
+
const normalizeClientRequestArgs_1 = require("./utils/normalizeClientRequestArgs");
|
|
7
|
+
const log = (0, debug_1.debug)('http request');
|
|
33
8
|
function request(protocol, options) {
|
|
34
|
-
return
|
|
35
|
-
var args = [];
|
|
36
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
37
|
-
args[_i] = arguments[_i];
|
|
38
|
-
}
|
|
9
|
+
return (...args) => {
|
|
39
10
|
log('request call (protocol "%s"):', protocol, args);
|
|
40
|
-
|
|
11
|
+
const clientRequestArgs = (0, normalizeClientRequestArgs_1.normalizeClientRequestArgs)(`${protocol}:`, ...args);
|
|
41
12
|
return new NodeClientRequest_1.NodeClientRequest(clientRequestArgs, options);
|
|
42
13
|
};
|
|
43
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.request.js","sourceRoot":"","sources":["../../../src/interceptors/ClientRequest/http.request.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http.request.js","sourceRoot":"","sources":["../../../src/interceptors/ClientRequest/http.request.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAE7B,2DAI4B;AAC5B,mFAG2C;AAE3C,MAAM,GAAG,GAAG,IAAA,aAAK,EAAC,cAAc,CAAC,CAAA;AAEjC,SAAgB,OAAO,CAAC,QAAkB,EAAE,OAA0B;IACpE,OAAO,CAAC,GAAG,IAAuB,EAAiB,EAAE;QACnD,GAAG,CAAC,+BAA+B,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;QAEpD,MAAM,iBAAiB,GAAG,IAAA,uDAA0B,EAClD,GAAG,QAAQ,GAAG,EACd,GAAG,IAAI,CACR,CAAA;QACD,OAAO,IAAI,qCAAiB,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAA;IAC1D,CAAC,CAAA;AACH,CAAC;AAVD,0BAUC"}
|
|
@@ -1,82 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __values = (this && this.__values) || function(o) {
|
|
18
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
19
|
-
if (m) return m.call(o);
|
|
20
|
-
if (o && typeof o.length === "number") return {
|
|
21
|
-
next: function () {
|
|
22
|
-
if (o && i >= o.length) o = void 0;
|
|
23
|
-
return { value: o && o[i++], done: !o };
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
27
|
-
};
|
|
28
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
29
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
30
|
-
if (!m) return o;
|
|
31
|
-
var i = m.call(o), r, ar = [], e;
|
|
32
|
-
try {
|
|
33
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
34
|
-
}
|
|
35
|
-
catch (error) { e = { error: error }; }
|
|
36
|
-
finally {
|
|
37
|
-
try {
|
|
38
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
39
|
-
}
|
|
40
|
-
finally { if (e) throw e.error; }
|
|
41
|
-
}
|
|
42
|
-
return ar;
|
|
43
|
-
};
|
|
44
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
4
|
};
|
|
47
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
6
|
exports.ClientRequestInterceptor = void 0;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
7
|
+
const http_1 = __importDefault(require("http"));
|
|
8
|
+
const https_1 = __importDefault(require("https"));
|
|
9
|
+
const Interceptor_1 = require("../../Interceptor");
|
|
10
|
+
const http_get_1 = require("./http.get");
|
|
11
|
+
const http_request_1 = require("./http.request");
|
|
54
12
|
/**
|
|
55
13
|
* Intercept requests made via the `ClientRequest` class.
|
|
56
14
|
* Such requests include `http.get`, `https.request`, etc.
|
|
57
15
|
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
_this.modules.set('https', https_1.default);
|
|
65
|
-
return _this;
|
|
16
|
+
class ClientRequestInterceptor extends Interceptor_1.Interceptor {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(ClientRequestInterceptor.symbol);
|
|
19
|
+
this.modules = new Map();
|
|
20
|
+
this.modules.set('http', http_1.default);
|
|
21
|
+
this.modules.set('https', https_1.default);
|
|
66
22
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this_1.subscriptions.push(function () {
|
|
23
|
+
setup() {
|
|
24
|
+
const log = this.log.extend('setup');
|
|
25
|
+
for (const [protocol, requestModule] of this.modules) {
|
|
26
|
+
const { request: pureRequest, get: pureGet } = requestModule;
|
|
27
|
+
this.subscriptions.push(() => {
|
|
73
28
|
requestModule.request = pureRequest;
|
|
74
29
|
requestModule.get = pureGet;
|
|
75
30
|
log('native "%s" module restored!', protocol);
|
|
76
31
|
});
|
|
77
|
-
|
|
78
|
-
emitter:
|
|
79
|
-
log:
|
|
32
|
+
const options = {
|
|
33
|
+
emitter: this.emitter,
|
|
34
|
+
log: this.log,
|
|
80
35
|
};
|
|
81
36
|
// @ts-ignore
|
|
82
37
|
requestModule.request =
|
|
@@ -87,24 +42,9 @@ var ClientRequestInterceptor = /** @class */ (function (_super) {
|
|
|
87
42
|
// Force a line break.
|
|
88
43
|
(0, http_get_1.get)(protocol, options);
|
|
89
44
|
log('native "%s" module patched!', protocol);
|
|
90
|
-
};
|
|
91
|
-
var this_1 = this;
|
|
92
|
-
try {
|
|
93
|
-
for (var _b = __values(this.modules), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
94
|
-
var _d = __read(_c.value, 2), protocol = _d[0], requestModule = _d[1];
|
|
95
|
-
_loop_1(protocol, requestModule);
|
|
96
|
-
}
|
|
97
45
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
try {
|
|
101
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
102
|
-
}
|
|
103
|
-
finally { if (e_1) throw e_1.error; }
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
ClientRequestInterceptor.symbol = Symbol('http');
|
|
107
|
-
return ClientRequestInterceptor;
|
|
108
|
-
}(Interceptor_1.Interceptor));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
109
48
|
exports.ClientRequestInterceptor = ClientRequestInterceptor;
|
|
49
|
+
ClientRequestInterceptor.symbol = Symbol('http');
|
|
110
50
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interceptors/ClientRequest/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interceptors/ClientRequest/index.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AACvB,kDAAyB;AAEzB,mDAA+C;AAE/C,yCAAgC;AAChC,iDAAwC;AAOxC;;;GAGG;AACH,MAAa,wBAAyB,SAAQ,yBAAgC;IAI5E;QACE,KAAK,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAA;QAEtC,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAA;QACxB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,cAAI,CAAC,CAAA;QAC9B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,eAAK,CAAC,CAAA;IAClC,CAAC;IAES,KAAK;QACb,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QAEpC,KAAK,MAAM,CAAC,QAAQ,EAAE,aAAa,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE;YACpD,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,aAAa,CAAA;YAE5D,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE;gBAC3B,aAAa,CAAC,OAAO,GAAG,WAAW,CAAA;gBACnC,aAAa,CAAC,GAAG,GAAG,OAAO,CAAA;gBAE3B,GAAG,CAAC,8BAA8B,EAAE,QAAQ,CAAC,CAAA;YAC/C,CAAC,CAAC,CAAA;YAEF,MAAM,OAAO,GAAsB;gBACjC,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,GAAG,EAAE,IAAI,CAAC,GAAG;aACd,CAAA;YAED,aAAa;YACb,aAAa,CAAC,OAAO;gBACnB,sBAAsB;gBACtB,IAAA,sBAAO,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;YAE5B,aAAa;YACb,aAAa,CAAC,GAAG;gBACf,sBAAsB;gBACtB,IAAA,cAAG,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;YAExB,GAAG,CAAC,6BAA6B,EAAE,QAAQ,CAAC,CAAA;SAC7C;IACH,CAAC;;AA1CH,4DA2CC;AA1CQ,+BAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA"}
|
|
@@ -1,55 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
|
-
var __values = (this && this.__values) || function(o) {
|
|
28
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
29
|
-
if (m) return m.call(o);
|
|
30
|
-
if (o && typeof o.length === "number") return {
|
|
31
|
-
next: function () {
|
|
32
|
-
if (o && i >= o.length) o = void 0;
|
|
33
|
-
return { value: o && o[i++], done: !o };
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.cloneIncomingMessage = exports.IS_CLONE = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
4
|
+
const http_1 = require("http");
|
|
5
|
+
const stream_1 = require("stream");
|
|
42
6
|
exports.IS_CLONE = Symbol('isClone');
|
|
43
7
|
/**
|
|
44
8
|
* Clones a given `http.IncomingMessage` instance.
|
|
45
9
|
*/
|
|
46
10
|
function cloneIncomingMessage(message) {
|
|
47
|
-
|
|
11
|
+
const clone = message.pipe(new stream_1.PassThrough());
|
|
48
12
|
// Inherit all direct "IncomingMessage" properties.
|
|
49
13
|
inheritProperties(message, clone);
|
|
50
14
|
// Deeply inherit the message prototypes (Readable, Stream, EventEmitter, etc.).
|
|
51
|
-
|
|
52
|
-
getPrototypes(clone).forEach(
|
|
15
|
+
const clonedPrototype = Object.create(http_1.IncomingMessage.prototype);
|
|
16
|
+
getPrototypes(clone).forEach((prototype) => {
|
|
53
17
|
inheritProperties(prototype, clonedPrototype);
|
|
54
18
|
});
|
|
55
19
|
Object.setPrototypeOf(clone, clonedPrototype);
|
|
@@ -64,8 +28,8 @@ exports.cloneIncomingMessage = cloneIncomingMessage;
|
|
|
64
28
|
* Returns a list of all prototypes the given object extends.
|
|
65
29
|
*/
|
|
66
30
|
function getPrototypes(source) {
|
|
67
|
-
|
|
68
|
-
|
|
31
|
+
const prototypes = [];
|
|
32
|
+
let current = source;
|
|
69
33
|
while ((current = Object.getPrototypeOf(current))) {
|
|
70
34
|
prototypes.push(current);
|
|
71
35
|
}
|
|
@@ -78,27 +42,19 @@ function getPrototypes(source) {
|
|
|
78
42
|
* @param target Object to inherit the properties from.
|
|
79
43
|
*/
|
|
80
44
|
function inheritProperties(source, target) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
var descriptor = Object.getOwnPropertyDescriptor(source, property);
|
|
90
|
-
if (!descriptor) {
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
Object.defineProperty(target, property, descriptor);
|
|
45
|
+
const properties = [
|
|
46
|
+
...Object.getOwnPropertyNames(source),
|
|
47
|
+
...Object.getOwnPropertySymbols(source),
|
|
48
|
+
];
|
|
49
|
+
for (const property of properties) {
|
|
50
|
+
if (target.hasOwnProperty(property)) {
|
|
51
|
+
continue;
|
|
94
52
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
try {
|
|
99
|
-
if (properties_1_1 && !properties_1_1.done && (_a = properties_1.return)) _a.call(properties_1);
|
|
53
|
+
const descriptor = Object.getOwnPropertyDescriptor(source, property);
|
|
54
|
+
if (!descriptor) {
|
|
55
|
+
continue;
|
|
100
56
|
}
|
|
101
|
-
|
|
57
|
+
Object.defineProperty(target, property, descriptor);
|
|
102
58
|
}
|
|
103
59
|
}
|
|
104
60
|
//# sourceMappingURL=cloneIncomingMessage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloneIncomingMessage.js","sourceRoot":"","sources":["../../../../src/interceptors/ClientRequest/utils/cloneIncomingMessage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cloneIncomingMessage.js","sourceRoot":"","sources":["../../../../src/interceptors/ClientRequest/utils/cloneIncomingMessage.ts"],"names":[],"mappings":";;;AAAA,+BAAsC;AACtC,mCAAoC;AAEvB,QAAA,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;AAMzC;;GAEG;AACH,SAAgB,oBAAoB,CAClC,OAAwB;IAExB,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,oBAAW,EAAE,CAAC,CAAA;IAE7C,mDAAmD;IACnD,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAEjC,gFAAgF;IAChF,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,sBAAe,CAAC,SAAS,CAAC,CAAA;IAChE,aAAa,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;QACzC,iBAAiB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAA;IAC/C,CAAC,CAAC,CAAA;IACF,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,eAAe,CAAC,CAAA;IAE7C,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,gBAAQ,EAAE;QACrC,UAAU,EAAE,IAAI;QAChB,KAAK,EAAE,IAAI;KACZ,CAAC,CAAA;IAEF,OAAO,KAAyC,CAAA;AAClD,CAAC;AArBD,oDAqBC;AAED;;GAEG;AACH,SAAS,aAAa,CAAC,MAAc;IACnC,MAAM,UAAU,GAAa,EAAE,CAAA;IAC/B,IAAI,OAAO,GAAG,MAAM,CAAA;IAEpB,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,EAAE;QACjD,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;KACzB;IAED,OAAO,UAAU,CAAA;AACnB,CAAC;AAED;;;;;GAKG;AACH,SAAS,iBAAiB,CAAC,MAAc,EAAE,MAAc;IACvD,MAAM,UAAU,GAAG;QACjB,GAAG,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC;QACrC,GAAG,MAAM,CAAC,qBAAqB,CAAC,MAAM,CAAC;KACxC,CAAA;IAED,KAAK,MAAM,QAAQ,IAAI,UAAU,EAAE;QACjC,IAAI,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE;YACnC,SAAQ;SACT;QAED,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;QACpE,IAAI,CAAC,UAAU,EAAE;YACf,SAAQ;SACT;QAED,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAA;KACpD;AACH,CAAC"}
|
|
@@ -1,49 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __values = (this && this.__values) || function(o) {
|
|
3
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
-
if (m) return m.call(o);
|
|
5
|
-
if (o && typeof o.length === "number") return {
|
|
6
|
-
next: function () {
|
|
7
|
-
if (o && i >= o.length) o = void 0;
|
|
8
|
-
return { value: o && o[i++], done: !o };
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.createRequest = void 0;
|
|
15
|
-
|
|
16
|
-
|
|
4
|
+
const web_fetch_1 = require("@remix-run/web-fetch");
|
|
5
|
+
const headers_polyfill_1 = require("headers-polyfill");
|
|
17
6
|
/**
|
|
18
7
|
* Creates a Fetch API `Request` instance from the given `http.ClientRequest`.
|
|
19
8
|
*/
|
|
20
9
|
function createRequest(clientRequest) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var headerValue = outgoingHeaders[headerName];
|
|
10
|
+
const headers = new headers_polyfill_1.Headers();
|
|
11
|
+
const outgoingHeaders = clientRequest.getHeaders();
|
|
12
|
+
for (const headerName in outgoingHeaders) {
|
|
13
|
+
const headerValue = outgoingHeaders[headerName];
|
|
26
14
|
if (!headerValue) {
|
|
27
15
|
continue;
|
|
28
16
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
var value = valuesList_1_1.value;
|
|
33
|
-
headers.append(headerName, value.toString());
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
37
|
-
finally {
|
|
38
|
-
try {
|
|
39
|
-
if (valuesList_1_1 && !valuesList_1_1.done && (_a = valuesList_1.return)) _a.call(valuesList_1);
|
|
40
|
-
}
|
|
41
|
-
finally { if (e_1) throw e_1.error; }
|
|
17
|
+
const valuesList = Array.prototype.concat([], headerValue);
|
|
18
|
+
for (const value of valuesList) {
|
|
19
|
+
headers.append(headerName, value.toString());
|
|
42
20
|
}
|
|
43
21
|
}
|
|
44
22
|
return new web_fetch_1.Request(clientRequest.url, {
|
|
45
23
|
method: clientRequest.method || 'GET',
|
|
46
|
-
headers
|
|
24
|
+
headers,
|
|
47
25
|
credentials: 'same-origin',
|
|
48
26
|
body: clientRequest.requestBuffer,
|
|
49
27
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRequest.js","sourceRoot":"","sources":["../../../../src/interceptors/ClientRequest/utils/createRequest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createRequest.js","sourceRoot":"","sources":["../../../../src/interceptors/ClientRequest/utils/createRequest.ts"],"names":[],"mappings":";;;AAAA,oDAA8C;AAC9C,uDAA0C;AAG1C;;GAEG;AACH,SAAgB,aAAa,CAAC,aAAgC;IAC5D,MAAM,OAAO,GAAG,IAAI,0BAAO,EAAE,CAAA;IAE7B,MAAM,eAAe,GAAG,aAAa,CAAC,UAAU,EAAE,CAAA;IAClD,KAAK,MAAM,UAAU,IAAI,eAAe,EAAE;QACxC,MAAM,WAAW,GAAG,eAAe,CAAC,UAAU,CAAC,CAAA;QAE/C,IAAI,CAAC,WAAW,EAAE;YAChB,SAAQ;SACT;QAED,MAAM,UAAU,GAAG,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,EAAE,WAAW,CAAC,CAAA;QAC1D,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE;YAC9B,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAA;SAC7C;KACF;IAED,OAAO,IAAI,mBAAO,CAAC,aAAa,CAAC,GAAG,EAAE;QACpC,MAAM,EAAE,aAAa,CAAC,MAAM,IAAI,KAAK;QACrC,OAAO;QACP,WAAW,EAAE,aAAa;QAC1B,IAAI,EAAE,aAAa,CAAC,aAAa;KAClC,CAAC,CAAA;AACJ,CAAC;AAvBD,sCAuBC"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createResponse = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const web_fetch_1 = require("@remix-run/web-fetch");
|
|
5
|
+
const headers_polyfill_1 = require("headers-polyfill");
|
|
6
6
|
/**
|
|
7
7
|
* Creates a Fetch API `Response` instance from the given
|
|
8
8
|
* `http.IncomingMessage` instance.
|
|
9
9
|
*/
|
|
10
10
|
function createResponse(message) {
|
|
11
|
-
|
|
12
|
-
start
|
|
13
|
-
message.on('data',
|
|
14
|
-
message.on('end',
|
|
11
|
+
const readable = new web_fetch_1.ReadableStream({
|
|
12
|
+
start(controller) {
|
|
13
|
+
message.on('data', (chunk) => controller.enqueue(chunk));
|
|
14
|
+
message.on('end', () => controller.close());
|
|
15
15
|
},
|
|
16
16
|
});
|
|
17
17
|
return new web_fetch_1.Response(readable, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createResponse.js","sourceRoot":"","sources":["../../../../src/interceptors/ClientRequest/utils/createResponse.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"createResponse.js","sourceRoot":"","sources":["../../../../src/interceptors/ClientRequest/utils/createResponse.ts"],"names":[],"mappings":";;;AACA,oDAA+D;AAC/D,uDAAkD;AAElD;;;GAGG;AACH,SAAgB,cAAc,CAAC,OAAwB;IACrD,MAAM,QAAQ,GAAG,IAAI,0BAAc,CAAC;QAClC,KAAK,CAAC,UAAU;YACd,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;YACxD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAA;QAC7C,CAAC;KACF,CAAC,CAAA;IAEF,OAAO,IAAI,oBAAQ,CAAC,QAAQ,EAAE;QAC5B,MAAM,EAAE,OAAO,CAAC,UAAU;QAC1B,UAAU,EAAE,OAAO,CAAC,aAAa;QACjC,OAAO,EAAE,IAAA,kCAAe,EAAC,OAAO,CAAC,OAAO,CAAC;KAC1C,CAAC,CAAA;AACJ,CAAC;AAbD,wCAaC"}
|
|
@@ -20,34 +20,34 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
22
|
exports.getIncomingMessageBody = void 0;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
27
|
function getIncomingMessageBody(response) {
|
|
28
|
-
return new Promise(
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
29
|
log('cloning the original response...');
|
|
30
30
|
// Pipe the original response to support non-clone
|
|
31
31
|
// "response" input. No need to clone the response,
|
|
32
32
|
// as we always have access to the full "response" input,
|
|
33
33
|
// either a clone or an original one (in tests).
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
const responseClone = response.pipe(new stream_1.PassThrough());
|
|
35
|
+
const stream = response.headers['content-encoding'] === 'gzip'
|
|
36
36
|
? responseClone.pipe(zlib.createGunzip())
|
|
37
37
|
: responseClone;
|
|
38
|
-
|
|
38
|
+
const encoding = response.readableEncoding || 'utf8';
|
|
39
39
|
stream.setEncoding(encoding);
|
|
40
40
|
log('using encoding:', encoding);
|
|
41
|
-
|
|
42
|
-
stream.on('data',
|
|
41
|
+
let body = '';
|
|
42
|
+
stream.on('data', (responseBody) => {
|
|
43
43
|
log('response body read:', responseBody);
|
|
44
44
|
body += responseBody;
|
|
45
45
|
});
|
|
46
|
-
stream.once('end',
|
|
46
|
+
stream.once('end', () => {
|
|
47
47
|
log('response body end');
|
|
48
48
|
resolve(body);
|
|
49
49
|
});
|
|
50
|
-
stream.once('error',
|
|
50
|
+
stream.once('error', (error) => {
|
|
51
51
|
log('error while reading response body:', error);
|
|
52
52
|
reject(error);
|
|
53
53
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIncomingMessageBody.js","sourceRoot":"","sources":["../../../../src/interceptors/ClientRequest/utils/getIncomingMessageBody.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA
|
|
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"}
|