@mswjs/interceptors
Advanced tools
Comparing version 0.34.3 to 0.35.0
@@ -8,3 +8,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkFXSPMSSQjs = require('./chunk-FXSPMSSQ.js'); | ||
var _chunk2CAGU4FTjs = require('./chunk-2CAGU4FT.js'); | ||
@@ -79,3 +79,3 @@ | ||
exports.BatchInterceptor = BatchInterceptor; exports.INTERNAL_REQUEST_ID_HEADER_NAME = _chunkTIPR373Rjs.INTERNAL_REQUEST_ID_HEADER_NAME; exports.IS_PATCHED_MODULE = _chunkFXSPMSSQjs.IS_PATCHED_MODULE; exports.Interceptor = _chunkTIPR373Rjs.Interceptor; exports.InterceptorReadyState = _chunkTIPR373Rjs.InterceptorReadyState; exports.createRequestId = _chunkTIPR373Rjs.createRequestId; exports.decodeBuffer = _chunkLK6DILFKjs.decodeBuffer; exports.deleteGlobalSymbol = _chunkTIPR373Rjs.deleteGlobalSymbol; exports.encodeBuffer = _chunkLK6DILFKjs.encodeBuffer; exports.getCleanUrl = getCleanUrl; exports.getGlobalSymbol = _chunkTIPR373Rjs.getGlobalSymbol; exports.isResponseWithoutBody = _chunkFXSPMSSQjs.isResponseWithoutBody; | ||
exports.BatchInterceptor = BatchInterceptor; exports.INTERNAL_REQUEST_ID_HEADER_NAME = _chunkTIPR373Rjs.INTERNAL_REQUEST_ID_HEADER_NAME; exports.IS_PATCHED_MODULE = _chunk2CAGU4FTjs.IS_PATCHED_MODULE; exports.Interceptor = _chunkTIPR373Rjs.Interceptor; exports.InterceptorReadyState = _chunkTIPR373Rjs.InterceptorReadyState; exports.createRequestId = _chunkTIPR373Rjs.createRequestId; exports.decodeBuffer = _chunkLK6DILFKjs.decodeBuffer; exports.deleteGlobalSymbol = _chunkTIPR373Rjs.deleteGlobalSymbol; exports.encodeBuffer = _chunkLK6DILFKjs.encodeBuffer; exports.getCleanUrl = getCleanUrl; exports.getGlobalSymbol = _chunkTIPR373Rjs.getGlobalSymbol; exports.isResponseWithoutBody = _chunk2CAGU4FTjs.isResponseWithoutBody; | ||
//# sourceMappingURL=index.js.map |
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkTPZUQHHYjs = require('../../chunk-TPZUQHHY.js'); | ||
require('../../chunk-EJYZ4HR3.js'); | ||
require('../../chunk-FXSPMSSQ.js'); | ||
var _chunkGIVU63INjs = require('../../chunk-GIVU63IN.js'); | ||
require('../../chunk-FYSUKT3F.js'); | ||
require('../../chunk-2CAGU4FT.js'); | ||
require('../../chunk-TIPR373R.js'); | ||
exports.FetchInterceptor = _chunkTPZUQHHYjs.FetchInterceptor; | ||
exports.FetchInterceptor = _chunkGIVU63INjs.FetchInterceptor; | ||
//# sourceMappingURL=index.js.map |
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkNBHFK2DJjs = require('../../chunk-NBHFK2DJ.js'); | ||
var _chunkYU6EJD6Ujs = require('../../chunk-YU6EJD6U.js'); | ||
require('../../chunk-LK6DILFK.js'); | ||
require('../../chunk-EJYZ4HR3.js'); | ||
require('../../chunk-FXSPMSSQ.js'); | ||
require('../../chunk-FYSUKT3F.js'); | ||
require('../../chunk-2CAGU4FT.js'); | ||
require('../../chunk-TIPR373R.js'); | ||
exports.XMLHttpRequestInterceptor = _chunkNBHFK2DJjs.XMLHttpRequestInterceptor; | ||
exports.XMLHttpRequestInterceptor = _chunkYU6EJD6Ujs.XMLHttpRequestInterceptor; | ||
//# sourceMappingURL=index.js.map |
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkNBHFK2DJjs = require('../chunk-NBHFK2DJ.js'); | ||
var _chunkYU6EJD6Ujs = require('../chunk-YU6EJD6U.js'); | ||
require('../chunk-LK6DILFK.js'); | ||
var _chunkTPZUQHHYjs = require('../chunk-TPZUQHHY.js'); | ||
require('../chunk-EJYZ4HR3.js'); | ||
require('../chunk-FXSPMSSQ.js'); | ||
var _chunkGIVU63INjs = require('../chunk-GIVU63IN.js'); | ||
require('../chunk-FYSUKT3F.js'); | ||
require('../chunk-2CAGU4FT.js'); | ||
require('../chunk-TIPR373R.js'); | ||
@@ -14,4 +14,4 @@ | ||
var browser_default = [ | ||
new (0, _chunkTPZUQHHYjs.FetchInterceptor)(), | ||
new (0, _chunkNBHFK2DJjs.XMLHttpRequestInterceptor)() | ||
new (0, _chunkGIVU63INjs.FetchInterceptor)(), | ||
new (0, _chunkYU6EJD6Ujs.XMLHttpRequestInterceptor)() | ||
]; | ||
@@ -18,0 +18,0 @@ |
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunk42632LKHjs = require('./chunk-42632LKH.js'); | ||
var _chunkPGTBKPWNjs = require('./chunk-PGTBKPWN.js'); | ||
@@ -19,3 +19,3 @@ | ||
var _chunkYGM3BCJUjs = require('./chunk-YGM3BCJU.js'); | ||
var _chunkAABH3XLQjs = require('./chunk-AABH3XLQ.js'); | ||
@@ -39,3 +39,3 @@ // src/utils/getCleanUrl.ts | ||
exports.BatchInterceptor = _chunk42632LKHjs.BatchInterceptor; exports.INTERNAL_REQUEST_ID_HEADER_NAME = _chunkYGM3BCJUjs.INTERNAL_REQUEST_ID_HEADER_NAME; exports.IS_PATCHED_MODULE = _chunkIDEEMJ3Fjs.IS_PATCHED_MODULE; exports.Interceptor = _chunkYGM3BCJUjs.Interceptor; exports.InterceptorReadyState = _chunkYGM3BCJUjs.InterceptorReadyState; exports.createRequestId = _chunkYGM3BCJUjs.createRequestId; exports.decodeBuffer = _chunkLK6DILFKjs.decodeBuffer; exports.deleteGlobalSymbol = _chunkYGM3BCJUjs.deleteGlobalSymbol; exports.encodeBuffer = _chunkLK6DILFKjs.encodeBuffer; exports.getCleanUrl = getCleanUrl; exports.getGlobalSymbol = _chunkYGM3BCJUjs.getGlobalSymbol; exports.isResponseWithoutBody = _chunkYGM3BCJUjs.isResponseWithoutBody; | ||
exports.BatchInterceptor = _chunkPGTBKPWNjs.BatchInterceptor; exports.INTERNAL_REQUEST_ID_HEADER_NAME = _chunkAABH3XLQjs.INTERNAL_REQUEST_ID_HEADER_NAME; exports.IS_PATCHED_MODULE = _chunkIDEEMJ3Fjs.IS_PATCHED_MODULE; exports.Interceptor = _chunkAABH3XLQjs.Interceptor; exports.InterceptorReadyState = _chunkAABH3XLQjs.InterceptorReadyState; exports.createRequestId = _chunkAABH3XLQjs.createRequestId; exports.decodeBuffer = _chunkLK6DILFKjs.decodeBuffer; exports.deleteGlobalSymbol = _chunkAABH3XLQjs.deleteGlobalSymbol; exports.encodeBuffer = _chunkLK6DILFKjs.encodeBuffer; exports.getCleanUrl = getCleanUrl; exports.getGlobalSymbol = _chunkAABH3XLQjs.getGlobalSymbol; exports.isResponseWithoutBody = _chunkAABH3XLQjs.isResponseWithoutBody; | ||
//# sourceMappingURL=index.js.map |
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkWTJL7BRVjs = require('../../chunk-WTJL7BRV.js'); | ||
require('../../chunk-TQD7SQGP.js'); | ||
require('../../chunk-YGM3BCJU.js'); | ||
var _chunkBMRE2LOXjs = require('../../chunk-BMRE2LOX.js'); | ||
require('../../chunk-VCUEA4PL.js'); | ||
require('../../chunk-AABH3XLQ.js'); | ||
exports.ClientRequestInterceptor = _chunkWTJL7BRVjs.ClientRequestInterceptor; | ||
exports.ClientRequestInterceptor = _chunkBMRE2LOXjs.ClientRequestInterceptor; | ||
//# sourceMappingURL=index.js.map |
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkW4AQXISMjs = require('../../chunk-W4AQXISM.js'); | ||
var _chunkWFQAQCYYjs = require('../../chunk-WFQAQCYY.js'); | ||
require('../../chunk-IDEEMJ3F.js'); | ||
require('../../chunk-TQD7SQGP.js'); | ||
require('../../chunk-YGM3BCJU.js'); | ||
require('../../chunk-VCUEA4PL.js'); | ||
require('../../chunk-AABH3XLQ.js'); | ||
exports.FetchInterceptor = _chunkW4AQXISMjs.FetchInterceptor; | ||
exports.FetchInterceptor = _chunkWFQAQCYYjs.FetchInterceptor; | ||
//# sourceMappingURL=index.js.map |
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunk6L3UERDRjs = require('../../chunk-6L3UERDR.js'); | ||
var _chunkFFSJ6QLAjs = require('../../chunk-FFSJ6QLA.js'); | ||
require('../../chunk-LK6DILFK.js'); | ||
require('../../chunk-IDEEMJ3F.js'); | ||
require('../../chunk-TQD7SQGP.js'); | ||
require('../../chunk-YGM3BCJU.js'); | ||
require('../../chunk-VCUEA4PL.js'); | ||
require('../../chunk-AABH3XLQ.js'); | ||
exports.XMLHttpRequestInterceptor = _chunk6L3UERDRjs.XMLHttpRequestInterceptor; | ||
exports.XMLHttpRequestInterceptor = _chunkFFSJ6QLAjs.XMLHttpRequestInterceptor; | ||
//# sourceMappingURL=index.js.map |
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkWTJL7BRVjs = require('../chunk-WTJL7BRV.js'); | ||
var _chunkBMRE2LOXjs = require('../chunk-BMRE2LOX.js'); | ||
var _chunk6L3UERDRjs = require('../chunk-6L3UERDR.js'); | ||
var _chunkFFSJ6QLAjs = require('../chunk-FFSJ6QLA.js'); | ||
require('../chunk-LK6DILFK.js'); | ||
var _chunkW4AQXISMjs = require('../chunk-W4AQXISM.js'); | ||
var _chunkWFQAQCYYjs = require('../chunk-WFQAQCYY.js'); | ||
require('../chunk-IDEEMJ3F.js'); | ||
require('../chunk-TQD7SQGP.js'); | ||
require('../chunk-YGM3BCJU.js'); | ||
require('../chunk-VCUEA4PL.js'); | ||
require('../chunk-AABH3XLQ.js'); | ||
// src/presets/node.ts | ||
var node_default = [ | ||
new (0, _chunkWTJL7BRVjs.ClientRequestInterceptor)(), | ||
new (0, _chunk6L3UERDRjs.XMLHttpRequestInterceptor)(), | ||
new (0, _chunkW4AQXISMjs.FetchInterceptor)() | ||
new (0, _chunkBMRE2LOXjs.ClientRequestInterceptor)(), | ||
new (0, _chunkFFSJ6QLAjs.XMLHttpRequestInterceptor)(), | ||
new (0, _chunkWFQAQCYYjs.FetchInterceptor)() | ||
]; | ||
@@ -21,0 +21,0 @@ |
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunk42632LKHjs = require('./chunk-42632LKH.js'); | ||
var _chunkPGTBKPWNjs = require('./chunk-PGTBKPWN.js'); | ||
var _chunkWTJL7BRVjs = require('./chunk-WTJL7BRV.js'); | ||
var _chunkBMRE2LOXjs = require('./chunk-BMRE2LOX.js'); | ||
var _chunk6L3UERDRjs = require('./chunk-6L3UERDR.js'); | ||
var _chunkFFSJ6QLAjs = require('./chunk-FFSJ6QLA.js'); | ||
require('./chunk-LK6DILFK.js'); | ||
@@ -15,9 +15,9 @@ require('./chunk-IDEEMJ3F.js'); | ||
var _chunkTQD7SQGPjs = require('./chunk-TQD7SQGP.js'); | ||
var _chunkVCUEA4PLjs = require('./chunk-VCUEA4PL.js'); | ||
var _chunkYGM3BCJUjs = require('./chunk-YGM3BCJU.js'); | ||
var _chunkAABH3XLQjs = require('./chunk-AABH3XLQ.js'); | ||
// src/RemoteHttpInterceptor.ts | ||
var RemoteHttpInterceptor = class extends _chunk42632LKHjs.BatchInterceptor { | ||
var RemoteHttpInterceptor = class extends _chunkPGTBKPWNjs.BatchInterceptor { | ||
constructor() { | ||
@@ -27,4 +27,4 @@ super({ | ||
interceptors: [ | ||
new (0, _chunkWTJL7BRVjs.ClientRequestInterceptor)(), | ||
new (0, _chunk6L3UERDRjs.XMLHttpRequestInterceptor)() | ||
new (0, _chunkBMRE2LOXjs.ClientRequestInterceptor)(), | ||
new (0, _chunkFFSJ6QLAjs.XMLHttpRequestInterceptor)() | ||
] | ||
@@ -96,3 +96,3 @@ }); | ||
} | ||
var _RemoteHttpResolver = class extends _chunkYGM3BCJUjs.Interceptor { | ||
var _RemoteHttpResolver = class extends _chunkAABH3XLQjs.Interceptor { | ||
constructor(options) { | ||
@@ -125,4 +125,4 @@ super(_RemoteHttpResolver.symbol); | ||
}); | ||
const controller = new (0, _chunkTQD7SQGPjs.RequestController)(request); | ||
await _chunkTQD7SQGPjs.handleRequest.call(void 0, { | ||
const controller = new (0, _chunkVCUEA4PLjs.RequestController)(request); | ||
await _chunkVCUEA4PLjs.handleRequest.call(void 0, { | ||
request, | ||
@@ -129,0 +129,0 @@ requestId: requestJson.id, |
{ | ||
"name": "@mswjs/interceptors", | ||
"description": "Low-level HTTP/HTTPS/XHR/fetch request interception library.", | ||
"version": "0.34.3", | ||
"version": "0.35.0", | ||
"main": "./lib/node/index.js", | ||
@@ -6,0 +6,0 @@ "module": "./lib/node/index.mjs", |
@@ -10,2 +10,5 @@ import { invariant } from 'outvariant' | ||
import { createRequestId } from '../../createRequestId' | ||
import { RESPONSE_STATUS_CODES_WITH_REDIRECT } from '../../utils/responseUtils' | ||
import { createNetworkError } from './utils/createNetworkError' | ||
import { followFetchRedirect } from './utils/followRedirect' | ||
@@ -72,2 +75,29 @@ export class FetchInterceptor extends Interceptor<HttpRequestEventMap> { | ||
/** | ||
* Undici's handling of following redirect responses. | ||
* Treat the "manual" redirect mode as a regular mocked response. | ||
* This way, the client can manually follow the redirect it receives. | ||
* @see https://github.com/nodejs/undici/blob/a6dac3149c505b58d2e6d068b97f4dc993da55f0/lib/web/fetch/index.js#L1173 | ||
*/ | ||
if (RESPONSE_STATUS_CODES_WITH_REDIRECT.has(response.status)) { | ||
// Reject the request promise if its `redirect` is set to `error` | ||
// and it receives a mocked redirect response. | ||
if (request.redirect === 'error') { | ||
responsePromise.reject(createNetworkError('unexpected redirect')) | ||
return | ||
} | ||
if (request.redirect === 'follow') { | ||
followFetchRedirect(request, response).then( | ||
(response) => { | ||
responsePromise.resolve(response) | ||
}, | ||
(reason) => { | ||
responsePromise.reject(reason) | ||
} | ||
) | ||
return | ||
} | ||
} | ||
if (this.emitter.listenerCount('response') > 0) { | ||
@@ -159,7 +189,1 @@ this.logger.info('emitting the "response" event...') | ||
} | ||
function createNetworkError(cause: unknown) { | ||
return Object.assign(new TypeError('Failed to fetch'), { | ||
cause, | ||
}) | ||
} |
@@ -11,2 +11,6 @@ import { isPropertyAccessible } from './isPropertyAccessible' | ||
export const RESPONSE_STATUS_CODES_WITH_REDIRECT = new Set([ | ||
301, 302, 303, 307, 308, | ||
]) | ||
/** | ||
@@ -13,0 +17,0 @@ * Returns a boolean indicating whether the given response status |
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
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
Network access
Supply chain riskThis module accesses the network.
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
1301034
205
17252
17