@mswjs/interceptors
Advanced tools
Comparing version 0.11.0 to 0.11.1
@@ -77,2 +77,3 @@ "use strict"; | ||
var getIncomingMessageBody_1 = require("./utils/getIncomingMessageBody"); | ||
var toIsoResponse_1 = require("../../utils/toIsoResponse"); | ||
var createDebug = require('debug'); | ||
@@ -253,8 +254,3 @@ function createClientRequestOverride(options) { | ||
response.complete = true; | ||
observer.emit('response', isoRequest, { | ||
status: mockedResponse.status || 200, | ||
statusText: mockedResponse.statusText || 'OK', | ||
headers: headers_utils_1.objectToHeaders(mockedResponse.headers || {}), | ||
body: mockedResponse.body, | ||
}); | ||
observer.emit('response', isoRequest, toIsoResponse_1.toIsoResponse(mockedResponse)); | ||
return [2 /*return*/, this]; | ||
@@ -268,10 +264,4 @@ } | ||
debug('using', pureMethod); | ||
// Decide whether to use HTTPS based on the URL protocol. | ||
// XHR can trigger http.request for HTTPS URL. | ||
if (url.protocol === 'https:') { | ||
request = pureMethod(options); | ||
} | ||
else { | ||
request = pureMethod(url.toString(), options); | ||
} | ||
// XMLHttpRequest can trigger "http.request" for https URL. | ||
request = pureMethod(url.toString(), options); | ||
// Propagate headers set after `ClientRequest` is constructed | ||
@@ -278,0 +268,0 @@ // onto the original request instance. |
@@ -79,3 +79,3 @@ "use strict"; | ||
} | ||
debug('%s.request original call', protocol); | ||
debug('%s.request original call', protocol, args); | ||
// @ts-ignore | ||
@@ -82,0 +82,0 @@ return originalRequest.apply(void 0, __spreadArray([], __read(args))); |
@@ -40,10 +40,16 @@ "use strict"; | ||
if (typeof args[1] === 'undefined' || typeof args[1] === 'function') { | ||
debug('request options not provided, deriving from the url', url); | ||
return getRequestOptionsByUrl_1.getRequestOptionsByUrl(url); | ||
} | ||
/** | ||
* Clone the request options to lock their state | ||
* at the moment they are provided to `ClientRequest`. | ||
* @see https://github.com/mswjs/interceptors/issues/86 | ||
*/ | ||
return args[1] ? cloneObject_1.cloneObject(args[1]) : {}; | ||
if (args[1]) { | ||
/** | ||
* Clone the request options to lock their state | ||
* at the moment they are provided to `ClientRequest`. | ||
* @see https://github.com/mswjs/interceptors/issues/86 | ||
*/ | ||
debug('request options exist, cloning...'); | ||
return cloneObject_1.cloneObject(args[1]); | ||
} | ||
debug('using an empty object as request options'); | ||
return {}; | ||
} | ||
@@ -50,0 +56,0 @@ function resolveCallback(args) { |
@@ -52,2 +52,3 @@ "use strict"; | ||
var headers_utils_1 = require("headers-utils"); | ||
var toIsoResponse_1 = require("../../utils/toIsoResponse"); | ||
var debug = require('debug')('fetch'); | ||
@@ -84,3 +85,3 @@ var interceptFetch = function (observer, resolver) { | ||
if (response) { | ||
isomorphicResponse = normalizeMockedResponse(response); | ||
isomorphicResponse = toIsoResponse_1.toIsoResponse(response); | ||
debug('derived isomorphic response', isomorphicResponse); | ||
@@ -120,10 +121,2 @@ observer.emit('response', isoRequest, isomorphicResponse); | ||
exports.interceptFetch = interceptFetch; | ||
function normalizeMockedResponse(response) { | ||
return { | ||
status: response.status || 200, | ||
statusText: response.statusText || 'OK', | ||
headers: headers_utils_1.objectToHeaders(response.headers || {}), | ||
body: response.body, | ||
}; | ||
} | ||
function normalizeFetchResponse(response) { | ||
@@ -130,0 +123,0 @@ return __awaiter(this, void 0, void 0, function () { |
@@ -75,2 +75,3 @@ "use strict"; | ||
var parseJson_1 = require("../../utils/parseJson"); | ||
var toIsoResponse_1 = require("../../utils/toIsoResponse"); | ||
var bufferFrom_1 = require("./utils/bufferFrom"); | ||
@@ -272,8 +273,3 @@ var createEvent_1 = require("./utils/createEvent"); | ||
_this.trigger('loadend'); | ||
observer.emit('response', isoRequest, { | ||
status: _this.status, | ||
statusText: _this.statusText, | ||
headers: headers_utils_1.objectToHeaders(mockedResponse.headers || {}), | ||
body: mockedResponse.body, | ||
}); | ||
observer.emit('response', isoRequest, toIsoResponse_1.toIsoResponse(mockedResponse)); | ||
} | ||
@@ -280,0 +276,0 @@ else { |
@@ -20,11 +20,18 @@ "use strict"; | ||
exports.cloneObject = void 0; | ||
var debug = require('debug')('cloneObject'); | ||
function isPlainObject(obj) { | ||
if (typeof obj === 'undefined') { | ||
var _a; | ||
debug('is plain object?', obj); | ||
if (obj == null || !((_a = obj.constructor) === null || _a === void 0 ? void 0 : _a.name)) { | ||
debug('given object is undefined, not a plain object...'); | ||
return false; | ||
} | ||
debug('checking the object constructor:', obj.constructor.name); | ||
return obj.constructor.name === 'Object'; | ||
} | ||
function cloneObject(obj) { | ||
debug('cloning object:', obj); | ||
var enumerableProperties = Object.entries(obj).reduce(function (acc, _a) { | ||
var _b = __read(_a, 2), key = _b[0], value = _b[1]; | ||
debug('analyzing key-value pair:', key, value); | ||
// Recursively clone only plain objects, omitting class instances. | ||
@@ -31,0 +38,0 @@ acc[key] = isPlainObject(value) ? cloneObject(value) : value; |
{ | ||
"name": "@mswjs/interceptors", | ||
"description": "Low-level HTTP/HTTPS/XHR/fetch request interception library.", | ||
"version": "0.11.0", | ||
"version": "0.11.1", | ||
"main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "typings": "lib/index.d.ts", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
156742
86
2205