@depup/mswjs__interceptors 0.43.0-depup.0 → 0.43.1-depup.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 +2 -2
- package/changes.json +1 -1
- package/lib/browser/interceptors/XMLHttpRequest/web.js +1 -1
- package/lib/browser/presets/browser.js +1 -1
- package/lib/browser/{web-BcKSQghf.js → web-EzmPOkVl.js} +12 -4
- package/lib/browser/{web-BcKSQghf.js.map → web-EzmPOkVl.js.map} +1 -1
- package/package.json +3 -3
- package/src/interceptors/XMLHttpRequest/xml-http-request-controller.ts +15 -3
package/README.md
CHANGED
|
@@ -13,8 +13,8 @@ npm install @depup/mswjs__interceptors
|
|
|
13
13
|
|
|
14
14
|
| Field | Value |
|
|
15
15
|
|-------|-------|
|
|
16
|
-
| Original | [@mswjs/interceptors](https://www.npmjs.com/package/@mswjs/interceptors) @ 0.43.
|
|
17
|
-
| Processed | 2026-09-
|
|
16
|
+
| Original | [@mswjs/interceptors](https://www.npmjs.com/package/@mswjs/interceptors) @ 0.43.1 |
|
|
17
|
+
| Processed | 2026-09-18 |
|
|
18
18
|
| Smoke test | passed |
|
|
19
19
|
| Deps updated | 0 |
|
|
20
20
|
|
package/changes.json
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as XMLHttpRequestInterceptor } from "../../web-
|
|
1
|
+
import { t as XMLHttpRequestInterceptor } from "../../web-EzmPOkVl.js";
|
|
2
2
|
export { XMLHttpRequestInterceptor };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as FetchInterceptor } from "../web-DUlFZEtz.js";
|
|
2
|
-
import { t as XMLHttpRequestInterceptor } from "../web-
|
|
2
|
+
import { t as XMLHttpRequestInterceptor } from "../web-EzmPOkVl.js";
|
|
3
3
|
//#region src/presets/browser.ts
|
|
4
4
|
/**
|
|
5
5
|
* A browser preset for the request interception regardless
|
|
@@ -692,12 +692,20 @@ var XMLHttpRequestController = class {
|
|
|
692
692
|
credentials: this.request.withCredentials ? "include" : "same-origin",
|
|
693
693
|
body: resolvedBody
|
|
694
694
|
});
|
|
695
|
-
|
|
695
|
+
const headers = fetchRequest.headers;
|
|
696
|
+
define(fetchRequest, "headers", createProxy(headers, { methodCall: ([methodName, args], invoke) => {
|
|
697
|
+
const result = invoke();
|
|
696
698
|
switch (methodName) {
|
|
697
699
|
case "append":
|
|
698
700
|
case "set": {
|
|
699
701
|
const [headerName, headerValue] = args;
|
|
700
|
-
|
|
702
|
+
/**
|
|
703
|
+
* @note Forward only the headers the Fetch API Request accepted.
|
|
704
|
+
* Forbidden request headers (e.g. "Cookie") are dropped silently
|
|
705
|
+
* by the request's headers guard, and forwarding them makes
|
|
706
|
+
* the browser refuse them with an error in the console.
|
|
707
|
+
*/
|
|
708
|
+
if (headers.has(headerName)) this.request.setRequestHeader(headerName, headerValue);
|
|
701
709
|
break;
|
|
702
710
|
}
|
|
703
711
|
case "delete": {
|
|
@@ -706,7 +714,7 @@ var XMLHttpRequestController = class {
|
|
|
706
714
|
break;
|
|
707
715
|
}
|
|
708
716
|
}
|
|
709
|
-
return
|
|
717
|
+
return result;
|
|
710
718
|
} }));
|
|
711
719
|
this.logger.verbose("converted request to a Fetch API Request!", fetchRequest);
|
|
712
720
|
return fetchRequest;
|
|
@@ -815,4 +823,4 @@ var XMLHttpRequestInterceptor = class extends Interceptor {
|
|
|
815
823
|
//#endregion
|
|
816
824
|
export { XMLHttpRequestInterceptor as t };
|
|
817
825
|
|
|
818
|
-
//# sourceMappingURL=web-
|
|
826
|
+
//# sourceMappingURL=web-EzmPOkVl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-BcKSQghf.js","names":[],"sources":["../../src/interceptors/XMLHttpRequest/utils/concat-array-buffer.ts","../../src/interceptors/XMLHttpRequest/polyfills/event-polyfill.ts","../../src/interceptors/XMLHttpRequest/polyfills/progress-event-polyfill.ts","../../src/interceptors/XMLHttpRequest/utils/create-event.ts","../../src/utils/find-property-source.ts","../../src/utils/create-proxy.ts","../../src/interceptors/XMLHttpRequest/utils/is-dom-parser-supported-type.ts","../../src/utils/parse-json.ts","../../src/interceptors/XMLHttpRequest/utils/create-response.ts","../../src/interceptors/XMLHttpRequest/utils/get-body-byte-length.ts","../../src/interceptors/XMLHttpRequest/xml-http-request-controller.ts","../../src/interceptors/XMLHttpRequest/xml-http-request-proxy.ts","../../src/interceptors/XMLHttpRequest/web.ts"],"sourcesContent":["/**\n * Concatenate two `Uint8Array` buffers.\n */\nexport function concatArrayBuffer(\n left: Uint8Array,\n right: Uint8Array\n) {\n const result = new Uint8Array(left.byteLength + right.byteLength)\n result.set(left, 0)\n result.set(right, left.byteLength)\n return result\n}\n","export class EventPolyfill implements Event {\n readonly NONE = 0\n readonly CAPTURING_PHASE = 1\n readonly AT_TARGET = 2\n readonly BUBBLING_PHASE = 3\n\n public type: string = ''\n public srcElement: EventTarget | null = null\n public target: EventTarget | null\n public currentTarget: EventTarget | null = null\n public eventPhase: number = 0\n public timeStamp: number\n public isTrusted: boolean = true\n public composed: boolean = false\n public cancelable: boolean = true\n public defaultPrevented: boolean = false\n public bubbles: boolean = true\n public lengthComputable: boolean = true\n public loaded: number = 0\n public total: number = 0\n\n cancelBubble: boolean = false\n returnValue: boolean = true\n\n constructor(\n type: string,\n options?: { target: EventTarget; currentTarget: EventTarget }\n ) {\n this.type = type\n this.target = options?.target || null\n this.currentTarget = options?.currentTarget || null\n this.timeStamp = Date.now()\n }\n\n public composedPath(): EventTarget[] {\n return []\n }\n\n public initEvent(type: string, bubbles?: boolean, cancelable?: boolean) {\n this.type = type\n this.bubbles = !!bubbles\n this.cancelable = !!cancelable\n }\n\n public preventDefault() {\n this.defaultPrevented = true\n }\n\n public stopPropagation() {}\n public stopImmediatePropagation() {}\n}\n","import { EventPolyfill } from './event-polyfill'\n\nexport class ProgressEventPolyfill extends EventPolyfill {\n readonly lengthComputable: boolean\n readonly composed: boolean\n readonly loaded: number\n readonly total: number\n\n constructor(type: string, init?: ProgressEventInit) {\n super(type)\n\n this.lengthComputable = init?.lengthComputable || false\n this.composed = init?.composed || false\n this.loaded = init?.loaded || 0\n this.total = init?.total || 0\n }\n}\n","import { EventPolyfill } from '../polyfills/event-polyfill'\nimport { ProgressEventPolyfill } from '../polyfills/progress-event-polyfill'\n\nconst SUPPORTS_PROGRESS_EVENT = typeof ProgressEvent !== 'undefined'\n\nexport function createEvent(\n target: XMLHttpRequest | XMLHttpRequestUpload,\n type: string,\n init?: ProgressEventInit\n): EventPolyfill | ProgressEvent {\n const progressEvents = [\n 'error',\n 'progress',\n 'loadstart',\n 'loadend',\n 'load',\n 'timeout',\n 'abort',\n ]\n\n /**\n * `ProgressEvent` is not supported in React Native.\n * @see https://github.com/mswjs/interceptors/issues/40\n */\n const ProgressEventClass = SUPPORTS_PROGRESS_EVENT\n ? ProgressEvent\n : ProgressEventPolyfill\n\n const event = progressEvents.includes(type)\n ? new ProgressEventClass(type, {\n lengthComputable: true,\n loaded: init?.loaded || 0,\n total: init?.total || 0,\n })\n : new EventPolyfill(type, {\n target,\n currentTarget: target,\n })\n\n return event\n}\n","/**\n * Returns the source object of the given property on the target object\n * (the target itself, any parent in its prototype, or null).\n */\nexport function findPropertySource(\n target: object,\n propertyName: string | symbol\n): object | null {\n if (!(propertyName in target)) {\n return null\n }\n\n const hasProperty = Object.prototype.hasOwnProperty.call(target, propertyName)\n if (hasProperty) {\n return target\n }\n\n const prototype = Reflect.getPrototypeOf(target)\n return prototype ? findPropertySource(prototype, propertyName) : null\n}\n","import { findPropertySource } from './find-property-source'\n\nexport interface ProxyOptions<Target extends Record<string, any>> {\n constructorCall?(args: Array<unknown>, next: NextFunction<Target>): Target\n\n methodCall?<F extends keyof Target>(\n this: Target,\n data: [methodName: F, args: Array<unknown>],\n next: NextFunction<void>\n ): void\n\n setProperty?(\n data: [propertyName: string | symbol, nextValue: unknown],\n next: NextFunction<boolean>\n ): boolean\n\n getProperty?(\n data: [propertyName: string | symbol, receiver: Target],\n next: NextFunction<void>\n ): void\n}\n\nexport type NextFunction<ReturnType> = () => ReturnType\n\nexport function createProxy<Target extends object>(\n target: Target,\n options: ProxyOptions<Target>\n): Target {\n const proxy = new Proxy(target, optionsToProxyHandler(options))\n\n return proxy\n}\n\nfunction optionsToProxyHandler<T extends Record<string, any>>(\n options: ProxyOptions<T>\n): ProxyHandler<T> {\n const { constructorCall, methodCall, getProperty, setProperty } = options\n const handler: ProxyHandler<T> = {}\n\n if (typeof constructorCall !== 'undefined') {\n handler.construct = function (target, args, newTarget) {\n const next = Reflect.construct.bind(null, target as any, args, newTarget)\n return constructorCall.call(newTarget, args, next)\n }\n }\n\n handler.set = function (target, propertyName, nextValue) {\n const next = () => {\n const propertySource = findPropertySource(target, propertyName) || target\n const ownDescriptors = Reflect.getOwnPropertyDescriptor(\n propertySource,\n propertyName\n )\n\n // Respect any custom setters present for this property.\n if (typeof ownDescriptors?.set !== 'undefined') {\n ownDescriptors.set.apply(target, [nextValue])\n return true\n }\n\n // Otherwise, set the property on the source.\n return Reflect.defineProperty(propertySource, propertyName, {\n writable: true,\n enumerable: true,\n configurable: true,\n value: nextValue,\n })\n }\n\n if (typeof setProperty !== 'undefined') {\n return setProperty.call(target, [propertyName, nextValue], next)\n }\n\n return next()\n }\n\n handler.get = function (target, propertyName, receiver) {\n /**\n * @note Using `Reflect.get()` here causes \"TypeError: Illegal invocation\".\n */\n const next = () => target[propertyName as any]\n\n const value =\n typeof getProperty !== 'undefined'\n ? getProperty.call(target, [propertyName, receiver], next)\n : next()\n\n if (typeof value === 'function') {\n return (...args: Array<any>) => {\n const next = value.bind(target, ...args)\n\n if (typeof methodCall !== 'undefined') {\n return methodCall.call(target, [propertyName as any, args], next)\n }\n\n return next()\n }\n }\n\n return value\n }\n\n return handler\n}\n","export function isDomParserSupportedType(\n type: string\n): type is DOMParserSupportedType {\n const supportedTypes: Array<DOMParserSupportedType> = [\n 'application/xhtml+xml',\n 'application/xml',\n 'image/svg+xml',\n 'text/html',\n 'text/xml',\n ]\n return supportedTypes.some((supportedType) => {\n return type.startsWith(supportedType)\n })\n}\n","/**\n * Parses a given string into JSON.\n * Gracefully handles invalid JSON by returning `null`.\n */\nexport function parseJson(data: string): Record<string, unknown> | null {\n try {\n const json = JSON.parse(data)\n return json\n } catch (_) {\n return null\n }\n}\n","import { FetchResponse } from '../../../utils/fetch-utils'\n\n/**\n * Creates a Fetch API `Response` instance from the given\n * `XMLHttpRequest` instance and a response body.\n */\nexport function createResponse(\n request: XMLHttpRequest,\n body: BodyInit | null\n): Response {\n /**\n * Handle XMLHttpRequest responses that must have null as the\n * response body when represented using Fetch API Response.\n * XMLHttpRequest response will always have an empty string\n * as the \"request.response\" in those cases, resulting in an error\n * when constructing a Response instance.\n * @see https://github.com/mswjs/interceptors/issues/379\n */\n const responseBodyOrNull = FetchResponse.isResponseWithBody(request.status)\n ? body\n : null\n\n return new FetchResponse(responseBodyOrNull, {\n url: request.responseURL,\n status: request.status,\n statusText: request.statusText,\n headers: createHeadersFromXMLHttpRequestHeaders(\n request.getAllResponseHeaders()\n ),\n })\n}\n\nfunction createHeadersFromXMLHttpRequestHeaders(headersString: string): Headers {\n const headers = new Headers()\n\n const lines = headersString.split(/[\\r\\n]+/)\n for (const line of lines) {\n if (line.trim() === '') {\n continue\n }\n\n const [name, ...parts] = line.split(': ')\n const value = parts.join(': ')\n\n headers.append(name, value)\n }\n\n return headers\n}\n","/**\n * Return a total byte length of the given request/response body.\n * If the `Content-Length` header is present, it will be used as the byte length.\n */\nexport async function getBodyByteLength(\n input: Request | Response\n): Promise<number> {\n const explicitContentLength = input.headers.get('content-length')\n\n if (explicitContentLength != null && explicitContentLength !== '') {\n return Number(explicitContentLength)\n }\n\n const buffer = await input.arrayBuffer()\n return buffer.byteLength\n}\n","import { until } from '@open-draft/until'\nimport { invariant } from 'outvariant'\nimport type { Logger } from '../../utils/logger'\nimport type { HttpResponseType } from '../../events/http'\nimport { concatArrayBuffer } from './utils/concat-array-buffer'\nimport { createEvent } from './utils/create-event'\nimport {\n decodeBuffer,\n encodeBuffer,\n toArrayBuffer,\n} from '../../utils/buffer-utils'\nimport { createProxy } from '../../utils/create-proxy'\nimport { isDomParserSupportedType } from './utils/is-dom-parser-supported-type'\nimport { parseJson } from '../../utils/parse-json'\nimport { createResponse } from './utils/create-response'\nimport { createRequestId } from '../../create-request-id'\nimport { getBodyByteLength } from './utils/get-body-byte-length'\nimport { FetchRequest, FetchResponse } from '../../utils/fetch-utils'\nimport { isResponseError } from '../../utils/response-utils'\n\nconst kIsRequestHandled = Symbol('kIsRequestHandled')\nconst kFetchRequest = Symbol('kFetchRequest')\nconst MAX_REDIRECTS = 20\n\n/**\n * An `XMLHttpRequest` instance controller that allows us\n * to handle any given request instance (e.g. responding to it).\n */\nexport class XMLHttpRequestController {\n public request: XMLHttpRequest\n public requestId: string\n public onRequest?: (\n this: XMLHttpRequestController,\n args: {\n request: Request\n requestId: string\n }\n ) => Promise<void>\n public onResponse?: (\n this: XMLHttpRequestController,\n args: {\n response: Response\n responseType: HttpResponseType\n request: Request\n requestId: string\n }\n ) => void;\n\n [kIsRequestHandled]: boolean;\n [kFetchRequest]?: Request\n\n private sync: boolean = false\n private method: string = 'GET'\n private url: URL = null as any\n private requestHeaders: Headers\n private responseBuffer: Uint8Array<ArrayBuffer>\n private redirectCount: number\n private events: Map<keyof XMLHttpRequestEventTargetEventMap, Array<Function>>\n private uploadEvents: Map<\n keyof XMLHttpRequestEventTargetEventMap,\n Array<Function>\n >\n\n constructor(\n readonly initialRequest: XMLHttpRequest,\n public logger: Logger\n ) {\n this[kIsRequestHandled] = false\n\n this.redirectCount = 0\n this.events = new Map()\n this.uploadEvents = new Map()\n this.requestId = createRequestId()\n this.requestHeaders = new Headers()\n this.responseBuffer = new Uint8Array()\n\n this.request = createProxy(initialRequest, {\n methodCall: ([methodName, args], invoke) => {\n switch (methodName) {\n case 'open': {\n const [method, url, async] = args as [\n string,\n string | undefined,\n boolean | undefined,\n ]\n\n this.sync = !(async ?? true)\n\n if (typeof url === 'undefined') {\n this.method = 'GET'\n this.url = toAbsoluteUrl(method)\n } else {\n this.method = method\n this.url = toAbsoluteUrl(url)\n }\n\n this.logger.verbose('open %s %s', this.method, this.url.href)\n\n return invoke()\n }\n\n case 'addEventListener': {\n const [eventName, listener] = args as [\n keyof XMLHttpRequestEventTargetEventMap,\n Function,\n ]\n\n this.registerEvent(eventName, listener)\n this.logger.verbose('addEventListener', eventName, listener)\n\n return invoke()\n }\n\n case 'setRequestHeader': {\n const [name, value] = args as [string, string]\n this.requestHeaders.set(name, value)\n\n this.logger.verbose('setRequestHeader', name, value)\n\n return invoke()\n }\n\n case 'send': {\n const [body] = args as [\n body?: XMLHttpRequestBodyInit | Document | null,\n ]\n\n if (this.sync) {\n console.warn(\n `Failed to intercept an XMLHttpRequest (${this.method} ${this.url}): synchronous requests are not supported. This request will be performed as-is.`\n )\n return invoke()\n }\n\n this.request.addEventListener('load', () => {\n if (typeof this.onResponse !== 'undefined') {\n // Create a Fetch API Response representation of whichever\n // response this XMLHttpRequest received. Note those may\n // be either a mocked and the original response.\n const fetchResponse = createResponse(\n this.request,\n /**\n * The `response` property is the right way to read\n * the ambiguous response body, as the request's \"responseType\" may differ.\n * @see https://xhr.spec.whatwg.org/#the-response-attribute\n */\n this.request.response\n )\n\n // Notify the consumer about the response.\n this.onResponse.call(this, {\n response: fetchResponse,\n responseType: this[kIsRequestHandled] ? 'mock' : 'original',\n request: fetchRequest,\n requestId: this.requestId!,\n })\n }\n })\n\n const requestBody =\n typeof body === 'string' ? encodeBuffer(body) : body\n\n // Delegate request handling to the consumer.\n const fetchRequest = this.toFetchApiRequest(requestBody)\n this[kFetchRequest] = fetchRequest.clone()\n\n /**\n * @note Start request handling on the next tick so that the user\n * could add event listeners for \"loadend\" before the interceptor fires it.\n */\n queueMicrotask(() => {\n const onceRequestSettled =\n this.onRequest?.call(this, {\n request: fetchRequest,\n requestId: this.requestId!,\n }) || Promise.resolve()\n\n onceRequestSettled.finally(() => {\n // If the consumer didn't handle the request (called `.respondWith()`) perform it as-is.\n if (!this[kIsRequestHandled]) {\n this.logger.verbose(\n 'request callback settled but request has not been handled (readystate %d), performing as-is...',\n this.request.readyState\n )\n\n return invoke()\n }\n })\n })\n\n break\n }\n\n default: {\n return invoke()\n }\n }\n },\n })\n\n /**\n * Proxy the `.upload` property to gather the event listeners/callbacks.\n */\n define(\n this.request,\n 'upload',\n createProxy(this.request.upload, {\n setProperty: ([propertyName, nextValue], invoke) => {\n switch (propertyName) {\n case 'onloadstart':\n case 'onprogress':\n case 'onaboart':\n case 'onerror':\n case 'onload':\n case 'ontimeout':\n case 'onloadend': {\n const eventName = propertyName.slice(\n 2\n ) as keyof XMLHttpRequestEventTargetEventMap\n\n this.registerUploadEvent(eventName, nextValue as Function)\n }\n }\n\n return invoke()\n },\n methodCall: ([methodName, args], invoke) => {\n switch (methodName) {\n case 'addEventListener': {\n const [eventName, listener] = args as [\n keyof XMLHttpRequestEventTargetEventMap,\n Function,\n ]\n this.registerUploadEvent(eventName, listener)\n this.logger.verbose('upload.addEventListener', eventName, listener)\n\n return invoke()\n }\n }\n },\n })\n )\n }\n\n private registerEvent(\n eventName: keyof XMLHttpRequestEventTargetEventMap,\n listener: Function\n ): void {\n const prevEvents = this.events.get(eventName) || []\n const nextEvents = prevEvents.concat(listener)\n this.events.set(eventName, nextEvents)\n\n this.logger.verbose('registered event \"%s\"', eventName, listener)\n }\n\n private registerUploadEvent(\n eventName: keyof XMLHttpRequestEventTargetEventMap,\n listener: Function\n ): void {\n const prevEvents = this.uploadEvents.get(eventName) || []\n const nextEvents = prevEvents.concat(listener)\n this.uploadEvents.set(eventName, nextEvents)\n\n this.logger.verbose('registered upload event \"%s\"', eventName, listener)\n }\n\n /**\n * Responds to the current request with the given\n * Fetch API `Response` instance.\n */\n public async respondWith(response: Response): Promise<void> {\n /**\n * @note Since `XMLHttpRequestController` delegates the handling of the responses\n * to the \"load\" event listener that doesn't distinguish between the mocked and original\n * responses, mark the request that had a mocked response with a corresponding symbol.\n *\n * Mark this request as having a mocked response immediately since\n * calculating request/response total body length is asynchronous.\n */\n this[kIsRequestHandled] = true\n\n this.logger.verbose(\n 'responding with a mocked response: %d %s',\n response.status,\n response.statusText\n )\n\n FetchResponse.setUrl(this.url.href, response)\n\n // Update the response getters to resolve against the mocked response.\n Object.defineProperties(this.request, {\n response: {\n enumerable: true,\n configurable: false,\n get: () => this.response,\n },\n responseText: {\n enumerable: true,\n configurable: false,\n get: () => this.responseText,\n },\n responseXML: {\n enumerable: true,\n configurable: false,\n get: () => this.responseXML,\n },\n })\n\n // 1. Fire a progress event named loadstart at this with 0 and 0.\n this.trigger('loadstart', this.request, { loaded: 0, total: 0 })\n\n // 2. Let requestBodyTransmitted be 0.\n let requestBodyTransmitted = 0\n let uploadComplete = false\n\n if (this[kFetchRequest]) {\n const requestBodyLength = await getBodyByteLength(\n this[kFetchRequest].clone()\n )\n\n // 5. If this’s upload complete flag is unset and this’s upload listener flag is set, then fire a progress event named loadstart at this’s upload object with requestBodyTransmitted and requestBodyLength.\n if (!uploadComplete) {\n this.trigger('loadstart', this.request.upload, {\n loaded: 0,\n total: requestBodyLength,\n })\n }\n\n const processRequestBodyChunkLength = (bytesLength: number) => {\n requestBodyTransmitted += bytesLength\n\n if (requestBodyTransmitted < requestBodyLength) {\n this.trigger('progress', this.request.upload, {\n loaded: requestBodyTransmitted,\n total: requestBodyLength,\n })\n }\n }\n\n const processRequestEndOfBody = () => {\n uploadComplete = true\n\n this.trigger('progress', this.request.upload, {\n loaded: requestBodyTransmitted,\n total: requestBodyLength,\n })\n this.trigger('load', this.request.upload, {\n loaded: requestBodyTransmitted,\n total: requestBodyLength,\n })\n this.trigger('loadend', this.request.upload, {\n loaded: requestBodyTransmitted,\n total: requestBodyLength,\n })\n }\n\n if (this[kFetchRequest]?.body != null) {\n const reader = this[kFetchRequest].body.getReader()\n\n while (true) {\n const { value, done } = await reader.read()\n\n if (done) {\n processRequestEndOfBody()\n break\n }\n\n processRequestBodyChunkLength(value.byteLength)\n }\n } else {\n processRequestEndOfBody()\n }\n }\n\n let timedOut = false\n const responseReadController = new AbortController()\n\n const requestErrorSteps = (\n event: keyof XMLHttpRequestEventTargetEventMap\n ) => {\n this.setReadyState(this.request.DONE)\n\n if (!uploadComplete) {\n this.trigger(event, this.request.upload, {\n loaded: 0,\n total: 0,\n })\n this.trigger('loadend', this.request.upload, {\n loaded: 0,\n total: 0,\n })\n }\n\n this.trigger(event, this.request, { loaded: 0, total: 0 })\n this.trigger('loadend', this.request, { loaded: 0, total: 0 })\n }\n\n const processResponse = async (response: Response) => {\n const handleErrors = () => {\n if (timedOut) {\n requestErrorSteps('timeout')\n } else if (responseReadController.signal.aborted) {\n requestErrorSteps('abort')\n } else if (isResponseError(response)) {\n requestErrorSteps('error')\n }\n }\n\n handleErrors()\n\n define(this.request, 'status', response.status)\n define(this.request, 'statusText', response.statusText)\n\n if (!this.request.responseURL) {\n define(this.request, 'responseURL', response.url)\n }\n\n if (isResponseError(response)) {\n return\n }\n\n /**\n * @note The response body length is derived ONLY from the \"content-length\" header.\n * If that response header is not set, the \"total\" in all progress events must be 0.\n */\n const responseBodyLength = Number(\n response.headers.get('content-length') ?? '0'\n )\n\n this.setReadyState(this.request.HEADERS_RECEIVED)\n\n let receivedBytes = 0\n let lastReceivedResponseBytesAt = performance.now()\n\n const processResponseBodyChunk = (bytesLength: number) => {\n receivedBytes += bytesLength\n\n const now = performance.now()\n const shouldBuffer =\n now - lastReceivedResponseBytesAt <= 60 &&\n receivedBytes < responseBodyLength\n lastReceivedResponseBytesAt = now\n\n if (shouldBuffer) {\n return\n }\n\n if (this.request.readyState === this.request.HEADERS_RECEIVED) {\n this.setReadyState(this.request.LOADING, false)\n }\n\n this.trigger('readystatechange', this.request)\n this.trigger('progress', this.request, {\n loaded: receivedBytes,\n total: responseBodyLength,\n })\n }\n\n const processResponseBodyError = () => {\n requestErrorSteps('error')\n }\n\n const processResponseEndOfBody = async () => {\n handleErrors()\n\n if (isResponseError(response)) {\n return\n }\n\n // 3. Let transmitted be xhr’s received bytes’s length.\n let transmitted = receivedBytes\n\n // 9. Fire an event named readystatechange at xhr.\n this.setReadyState(this.request.DONE)\n // 10. Fire a progress event named load at xhr with transmitted and length.\n this.trigger('load', this.request, {\n loaded: transmitted,\n total: responseBodyLength,\n })\n // 11. Fire a progress event named loadend at xhr with transmitted and length.\n this.trigger('loadend', this.request, {\n loaded: transmitted,\n total: responseBodyLength,\n })\n }\n\n // 7. If this’s response’s body is null, then run handle response end-of-body for this and return.\n if (response.body == null) {\n processResponseEndOfBody()\n } else {\n const reader = response.body.getReader()\n\n while (true) {\n if (responseReadController.signal.aborted) {\n break\n }\n\n try {\n const { value, done } = await reader.read()\n\n if (done) {\n processResponseEndOfBody()\n return\n }\n\n processResponseBodyChunk(value.byteLength)\n this.responseBuffer = concatArrayBuffer(this.responseBuffer, value)\n } catch {\n processResponseBodyError()\n }\n }\n }\n }\n\n // Redirects are followed as a part of the fetch controller. Since we don't have one,\n // retrieve the final response and then continue with processing it instead of the mocked one.\n const [redirectError, finalResponse] = await until(() => {\n return this.followRedirects(response)\n })\n\n if (redirectError) {\n return\n }\n\n processResponse(finalResponse)\n\n // 12.1, 12.2.\n if (this.request.timeout) {\n setTimeout(() => {\n if (this.request.readyState !== this.request.DONE) {\n timedOut = true\n responseReadController.abort()\n }\n }, this.request.timeout)\n }\n\n this.request.getResponseHeader = new Proxy(this.request.getResponseHeader, {\n apply: (_, __, args: [name: string]) => {\n this.logger.verbose('getResponseHeader', args[0])\n\n if (this.request.readyState < this.request.HEADERS_RECEIVED) {\n this.logger.verbose('headers not received yet, returning null')\n return null\n }\n\n const headerValue = finalResponse.headers.get(args[0])\n this.logger.verbose(\n 'resolved response header \"%s\" to',\n args[0],\n headerValue\n )\n\n return headerValue\n },\n })\n\n this.request.getAllResponseHeaders = new Proxy(\n this.request.getAllResponseHeaders,\n {\n apply: () => {\n this.logger.verbose('getAllResponseHeaders')\n\n if (this.request.readyState < this.request.HEADERS_RECEIVED) {\n this.logger.verbose('headers not received yet, returning empty string')\n return ''\n }\n\n const headersList = Array.from(finalResponse.headers)\n const allHeaders = headersList\n .map(([headerName, headerValue]) => {\n return `${headerName}: ${headerValue}`\n })\n .join('\\r\\n')\n\n this.logger.verbose('resolved all response headers to', allHeaders)\n\n return allHeaders\n },\n }\n )\n }\n\n private responseBufferToText(): string {\n return decodeBuffer(this.responseBuffer)\n }\n\n get response(): unknown {\n this.logger.verbose(\n 'getResponse (responseType: %s)',\n this.request.responseType\n )\n\n if (this.request.readyState !== this.request.DONE) {\n return null\n }\n\n switch (this.request.responseType) {\n case 'json': {\n const responseJson = parseJson(this.responseBufferToText())\n this.logger.verbose('resolved response JSON', responseJson)\n\n return responseJson\n }\n\n case 'arraybuffer': {\n const arrayBuffer = toArrayBuffer(this.responseBuffer)\n this.logger.verbose('resolved response ArrayBuffer', arrayBuffer)\n\n return arrayBuffer\n }\n\n case 'blob': {\n const mimeType =\n this.request.getResponseHeader('Content-Type') || 'text/plain'\n const responseBlob = new Blob([this.responseBufferToText()], {\n type: mimeType,\n })\n\n this.logger.verbose(\n 'resolved response Blob (mime type: %s)',\n responseBlob,\n mimeType\n )\n\n return responseBlob\n }\n\n default: {\n const responseText = this.responseBufferToText()\n this.logger.verbose(\n 'resolving \"%s\" response type as text',\n this.request.responseType,\n responseText\n )\n\n return responseText\n }\n }\n }\n\n get responseText(): string {\n /**\n * Throw when trying to read the response body as text when the\n * \"responseType\" doesn't expect text. This just respects the spec better.\n * @see https://xhr.spec.whatwg.org/#the-responsetext-attribute\n */\n invariant(\n this.request.responseType === '' || this.request.responseType === 'text',\n 'InvalidStateError: The object is in invalid state.'\n )\n\n if (\n this.request.readyState !== this.request.LOADING &&\n this.request.readyState !== this.request.DONE\n ) {\n return ''\n }\n\n const responseText = this.responseBufferToText()\n this.logger.verbose('getResponseText: \"%s\"', responseText)\n\n return responseText\n }\n\n get responseXML(): Document | null {\n invariant(\n this.request.responseType === '' ||\n this.request.responseType === 'document',\n 'InvalidStateError: The object is in invalid state.'\n )\n\n if (this.request.readyState !== this.request.DONE) {\n return null\n }\n\n const contentType = this.request.getResponseHeader('Content-Type') || ''\n\n if (typeof DOMParser === 'undefined') {\n console.warn(\n 'Cannot retrieve XMLHttpRequest response body as XML: DOMParser is not defined. You are likely using an environment that is not browser or does not polyfill browser globals correctly.'\n )\n return null\n }\n\n if (isDomParserSupportedType(contentType)) {\n return new DOMParser().parseFromString(\n this.responseBufferToText(),\n contentType\n )\n }\n\n return null\n }\n\n private async followRedirects(response: Response): Promise<Response> {\n const redirectLocation = response.headers.get('location')\n\n if (\n !redirectLocation ||\n !FetchResponse.isRedirectResponse(response.status)\n ) {\n return response\n }\n\n this.redirectCount++\n\n if (this.redirectCount > MAX_REDIRECTS) {\n throw new Error('Too many redirects')\n }\n\n const redirectUrl = new URL(redirectLocation, location.href)\n const redirectMethod = FetchResponse.isResponseWithBody(response.status)\n ? this.method\n : 'GET'\n\n const redirectResponse = await new Promise<Response>((resolve, reject) => {\n const request = new XMLHttpRequest()\n request.responseType = this.request.responseType\n\n request.addEventListener('load', () => {\n this.url = new URL(request.responseURL)\n resolve(createResponse(request, request.response))\n })\n\n request.addEventListener('error', () => {\n this.errorWith()\n reject(new Error('Redirect request failed'))\n })\n\n request.open(redirectMethod, redirectUrl.href)\n request.send()\n })\n\n return this.followRedirects(redirectResponse)\n }\n\n public errorWith(error?: Error): void {\n /**\n * @note Mark this request as handled even if it received a mock error.\n * This prevents the controller from trying to perform this request as-is.\n */\n this[kIsRequestHandled] = true\n this.logger.verbose('responding with an error')\n\n this.setReadyState(this.request.DONE)\n this.trigger('error', this.request)\n this.trigger('loadend', this.request)\n }\n\n /**\n * Transitions this request's `readyState` to the given one.\n */\n private setReadyState(\n nextReadyState: number,\n triggerReadyStateChangeEvent = true\n ): void {\n this.logger.verbose(\n 'setReadyState: %d -> %d',\n this.request.readyState,\n nextReadyState\n )\n\n if (this.request.readyState === nextReadyState) {\n this.logger.verbose('ready state identical, skipping transition...')\n return\n }\n\n define(this.request, 'readyState', nextReadyState)\n\n this.logger.verbose('set readyState to: %d', nextReadyState)\n\n if (!triggerReadyStateChangeEvent) {\n return\n }\n\n if (nextReadyState !== this.request.UNSENT) {\n this.logger.verbose('triggering \"readystatechange\" event...')\n\n this.trigger('readystatechange', this.request)\n }\n }\n\n /**\n * Triggers given event on the `XMLHttpRequest` instance.\n */\n private trigger<\n EventName extends keyof (XMLHttpRequestEventTargetEventMap & {\n readystatechange: ProgressEvent<XMLHttpRequestEventTarget>\n }),\n >(\n eventName: EventName,\n target: XMLHttpRequest | XMLHttpRequestUpload,\n options?: ProgressEventInit\n ): void {\n const callback = (target as XMLHttpRequest)[`on${eventName}`]\n const event = createEvent(target, eventName, options)\n\n this.logger.verbose('trigger \"%s\"', eventName, options || '')\n\n // Invoke direct callbacks.\n if (typeof callback === 'function') {\n this.logger.verbose('found a direct \"%s\" callback, calling...', eventName)\n callback.call(target as XMLHttpRequest, event)\n }\n\n // Invoke event listeners.\n const events =\n target instanceof XMLHttpRequestUpload ? this.uploadEvents : this.events\n\n for (const [registeredEventName, listeners] of events) {\n if (registeredEventName === eventName) {\n this.logger.verbose(\n 'found %d listener(s) for \"%s\" event, calling...',\n listeners.length,\n eventName\n )\n\n listeners.forEach((listener) => listener.call(target, event))\n }\n }\n }\n\n /**\n * Converts this `XMLHttpRequest` instance into a Fetch API `Request` instance.\n */\n private toFetchApiRequest(\n body: XMLHttpRequestBodyInit | Document | null | undefined\n ): Request {\n this.logger.verbose('converting request to a Fetch API Request...')\n\n // If the `Document` is used as the body of this XMLHttpRequest,\n // set its inner text as the Fetch API Request body.\n const resolvedBody =\n body instanceof Document ? body.documentElement.innerText : body\n\n const fetchRequest = new FetchRequest(this.url.href, {\n method: this.method,\n headers: this.requestHeaders,\n /**\n * @see https://xhr.spec.whatwg.org/#cross-origin-credentials\n */\n credentials: this.request.withCredentials ? 'include' : 'same-origin',\n body: resolvedBody,\n })\n\n const proxyHeaders = createProxy(fetchRequest.headers, {\n methodCall: ([methodName, args], invoke) => {\n // Forward the latest state of the internal request headers\n // because the interceptor might have modified them\n // without responding to the request.\n switch (methodName) {\n case 'append':\n case 'set': {\n const [headerName, headerValue] = args as [string, string]\n this.request.setRequestHeader(headerName, headerValue)\n break\n }\n\n case 'delete': {\n const [headerName] = args as [string]\n console.warn(\n `XMLHttpRequest: Cannot remove a \"${headerName}\" header from the Fetch API representation of the \"${fetchRequest.method} ${fetchRequest.url}\" request. XMLHttpRequest headers cannot be removed.`\n )\n break\n }\n }\n\n return invoke()\n },\n })\n define(fetchRequest, 'headers', proxyHeaders)\n // setRawRequest(fetchRequest, this.request)\n\n this.logger.verbose('converted request to a Fetch API Request!', fetchRequest)\n\n return fetchRequest\n }\n}\n\nfunction toAbsoluteUrl(url: string | URL): URL {\n /**\n * @note XMLHttpRequest interceptor may run in environments\n * that implement XMLHttpRequest but don't implement \"location\"\n * (for example, React Native). If that's the case, return the\n * input URL as-is (nothing to be relative to).\n * @see https://github.com/mswjs/msw/issues/1777\n */\n if (typeof location === 'undefined') {\n return new URL(url)\n }\n\n return new URL(url.toString(), location.href)\n}\n\nfunction define(\n target: object,\n property: string | symbol,\n value: unknown\n): void {\n Reflect.defineProperty(target, property, {\n // Ensure writable properties to allow redefining readonly properties.\n writable: true,\n enumerable: true,\n value,\n })\n}\n","import type { Emitter } from 'rettime'\nimport { HttpResponseEvent, type HttpRequestEventMap } from '../../events/http'\nimport { RequestController } from '../../request-controller'\nimport { XMLHttpRequestController } from './xml-http-request-controller'\nimport { handleRequest } from '../../utils/handle-request'\nimport type { Logger } from '../../utils/logger'\n\nexport interface XMLHttpRequestProxyOptions {\n emitter: Emitter<HttpRequestEventMap>\n logger: Logger\n}\n\n/**\n * Create a proxied `XMLHttpRequest` class.\n * The proxied class establishes spies on certain methods,\n * allowing us to intercept requests and respond to them.\n */\nexport function createXMLHttpRequestProxy({\n emitter,\n logger,\n}: XMLHttpRequestProxyOptions) {\n const XMLHttpRequestProxy = new Proxy(globalThis.XMLHttpRequest, {\n construct(target, args, newTarget) {\n logger.verbose('constructed new XMLHttpRequest')\n\n const originalRequest = Reflect.construct(\n target,\n args,\n newTarget\n ) as XMLHttpRequest\n\n /**\n * @note Forward prototype descriptors onto the proxied object.\n * XMLHttpRequest is implemented in JSDOM in a way that assigns\n * a bunch of descriptors, like \"set responseType()\" on the prototype.\n * With this propagation, we make sure that those descriptors trigger\n * when the user operates with the proxied request instance.\n */\n const prototypeDescriptors = Object.getOwnPropertyDescriptors(\n target.prototype\n )\n for (const propertyName in prototypeDescriptors) {\n Reflect.defineProperty(\n originalRequest,\n propertyName,\n prototypeDescriptors[propertyName]\n )\n }\n\n const xhrRequestController = new XMLHttpRequestController(\n originalRequest,\n logger\n )\n\n xhrRequestController.onRequest = async function ({ request, requestId }) {\n const controller = new RequestController(request, {\n passthrough: () => {\n this.logger.verbose(\n 'no mocked response received, performing request as-is...'\n )\n },\n respondWith: async (response) => {\n await this.respondWith(response)\n },\n errorWith: (reason) => {\n this.logger.verbose('request errored %o', { error: reason })\n\n if (reason instanceof Error) {\n this.errorWith(reason)\n }\n },\n }, {\n logger,\n requestId,\n })\n\n this.logger.verbose('awaiting mocked response')\n\n this.logger.verbose(\n 'emitting the \"request\" event for %s listener(s)...',\n emitter.listenerCount('request')\n )\n\n await handleRequest({\n initiator: this.request,\n request,\n requestId,\n controller,\n emitter,\n logger,\n })\n }\n\n xhrRequestController.onResponse = async function ({\n response,\n responseType,\n request,\n requestId,\n }) {\n this.logger.verbose(\n 'emitting the \"response\" event for %s listener(s)...',\n emitter.listenerCount('response')\n )\n\n await emitter.emitAsPromise(\n new HttpResponseEvent({\n initiator: this.request,\n response,\n responseType,\n request,\n requestId,\n })\n )\n }\n\n // Return the proxied request from the controller\n // so that the controller can react to the consumer's interactions\n // with this request (opening/sending/etc).\n return xhrRequestController.request\n },\n })\n\n return XMLHttpRequestProxy\n}\n","import { HttpRequestEventMap } from '../../events/http'\nimport { Interceptor } from '../../interceptor'\nimport { createXMLHttpRequestProxy } from './xml-http-request-proxy'\nimport { hasConfigurableGlobal } from '../../utils/has-configurable-global'\nimport { patchesRegistry } from '../../utils/patches-registry'\nimport { createLogger } from '../../utils/logger'\n\nconst logger = createLogger('xhr')\n\nexport class XMLHttpRequestInterceptor extends Interceptor<HttpRequestEventMap> {\n static symbol = Symbol.for('xhr-interceptor')\n\n protected predicate() {\n return hasConfigurableGlobal('XMLHttpRequest')\n }\n\n protected setup() {\n logger.verbose('patching \"XMLHttpRequest\"...')\n\n this.subscriptions.push(\n patchesRegistry.applyPatch(globalThis, 'XMLHttpRequest', () => {\n return createXMLHttpRequestProxy({\n emitter: this.emitter,\n logger,\n })\n })\n )\n\n logger.verbose(\n 'global \"XMLHttpRequest\" patched!',\n globalThis.XMLHttpRequest.name\n )\n }\n}\n"],"mappings":";;;;;;;;;;;AAGA,SAAgB,kBACd,MACA,OACA;CACA,MAAM,SAAS,IAAI,WAAW,KAAK,aAAa,MAAM,UAAU;CAChE,OAAO,IAAI,MAAM,CAAC;CAClB,OAAO,IAAI,OAAO,KAAK,UAAU;CACjC,OAAO;AACT;;;ACXA,IAAa,gBAAb,MAA4C;CAwB1C,YACE,MACA,SACA;EA1Bc,KAAA,OAAA;EACW,KAAA,kBAAA;EACN,KAAA,YAAA;EACK,KAAA,iBAAA;EAEJ,KAAA,OAAA;EACkB,KAAA,aAAA;EAEG,KAAA,gBAAA;EACf,KAAA,aAAA;EAEA,KAAA,YAAA;EACD,KAAA,WAAA;EACE,KAAA,aAAA;EACM,KAAA,mBAAA;EACT,KAAA,UAAA;EACS,KAAA,mBAAA;EACX,KAAA,SAAA;EACD,KAAA,QAAA;EAEC,KAAA,eAAA;EACD,KAAA,cAAA;EAMrB,KAAK,OAAO;EACZ,KAAK,SAAS,SAAS,UAAU;EACjC,KAAK,gBAAgB,SAAS,iBAAiB;EAC/C,KAAK,YAAY,KAAK,IAAI;CAC5B;CAEA,eAAqC;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ACD,KAAK,OAAO,QACV,yDACA,QAAQ,cAAc,UAAU,CAClC;GAEA,MAAM,QAAQ,cACZ,IAAI,kBAAkB;IACpB,WAAW,KAAK;IAChB;IACA;IACA;IACA;GACF,CAAC,CACH;EACF;EAKA,OAAO,qBAAqB;CAC9B,EACF,CAEyB;AAC3B;;;ACpHA,MAAM,SAAS,aAAa,KAAK;AAEjC,IAAa,4BAAb,cAA+C,YAAiC;;EAC9D,KAAA,SAAA,OAAO,IAAI,iBAAiB;;CAE5C,YAAsB;EACpB,OAAO,sBAAsB,gBAAgB;CAC/C;CAEA,QAAkB;EAChB,OAAO,QAAQ,gCAA8B;EAE7C,KAAK,cAAc,KACjB,gBAAgB,WAAW,YAAY,wBAAwB;GAC7D,OAAO,0BAA0B;IAC/B,SAAS,KAAK;IACd;GACF,CAAC;EACH,CAAC,CACH;EAEA,OAAO,QACL,sCACA,WAAW,eAAe,IAC5B;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"web-EzmPOkVl.js","names":[],"sources":["../../src/interceptors/XMLHttpRequest/utils/concat-array-buffer.ts","../../src/interceptors/XMLHttpRequest/polyfills/event-polyfill.ts","../../src/interceptors/XMLHttpRequest/polyfills/progress-event-polyfill.ts","../../src/interceptors/XMLHttpRequest/utils/create-event.ts","../../src/utils/find-property-source.ts","../../src/utils/create-proxy.ts","../../src/interceptors/XMLHttpRequest/utils/is-dom-parser-supported-type.ts","../../src/utils/parse-json.ts","../../src/interceptors/XMLHttpRequest/utils/create-response.ts","../../src/interceptors/XMLHttpRequest/utils/get-body-byte-length.ts","../../src/interceptors/XMLHttpRequest/xml-http-request-controller.ts","../../src/interceptors/XMLHttpRequest/xml-http-request-proxy.ts","../../src/interceptors/XMLHttpRequest/web.ts"],"sourcesContent":["/**\n * Concatenate two `Uint8Array` buffers.\n */\nexport function concatArrayBuffer(\n left: Uint8Array,\n right: Uint8Array\n) {\n const result = new Uint8Array(left.byteLength + right.byteLength)\n result.set(left, 0)\n result.set(right, left.byteLength)\n return result\n}\n","export class EventPolyfill implements Event {\n readonly NONE = 0\n readonly CAPTURING_PHASE = 1\n readonly AT_TARGET = 2\n readonly BUBBLING_PHASE = 3\n\n public type: string = ''\n public srcElement: EventTarget | null = null\n public target: EventTarget | null\n public currentTarget: EventTarget | null = null\n public eventPhase: number = 0\n public timeStamp: number\n public isTrusted: boolean = true\n public composed: boolean = false\n public cancelable: boolean = true\n public defaultPrevented: boolean = false\n public bubbles: boolean = true\n public lengthComputable: boolean = true\n public loaded: number = 0\n public total: number = 0\n\n cancelBubble: boolean = false\n returnValue: boolean = true\n\n constructor(\n type: string,\n options?: { target: EventTarget; currentTarget: EventTarget }\n ) {\n this.type = type\n this.target = options?.target || null\n this.currentTarget = options?.currentTarget || null\n this.timeStamp = Date.now()\n }\n\n public composedPath(): EventTarget[] {\n return []\n }\n\n public initEvent(type: string, bubbles?: boolean, cancelable?: boolean) {\n this.type = type\n this.bubbles = !!bubbles\n this.cancelable = !!cancelable\n }\n\n public preventDefault() {\n this.defaultPrevented = true\n }\n\n public stopPropagation() {}\n public stopImmediatePropagation() {}\n}\n","import { EventPolyfill } from './event-polyfill'\n\nexport class ProgressEventPolyfill extends EventPolyfill {\n readonly lengthComputable: boolean\n readonly composed: boolean\n readonly loaded: number\n readonly total: number\n\n constructor(type: string, init?: ProgressEventInit) {\n super(type)\n\n this.lengthComputable = init?.lengthComputable || false\n this.composed = init?.composed || false\n this.loaded = init?.loaded || 0\n this.total = init?.total || 0\n }\n}\n","import { EventPolyfill } from '../polyfills/event-polyfill'\nimport { ProgressEventPolyfill } from '../polyfills/progress-event-polyfill'\n\nconst SUPPORTS_PROGRESS_EVENT = typeof ProgressEvent !== 'undefined'\n\nexport function createEvent(\n target: XMLHttpRequest | XMLHttpRequestUpload,\n type: string,\n init?: ProgressEventInit\n): EventPolyfill | ProgressEvent {\n const progressEvents = [\n 'error',\n 'progress',\n 'loadstart',\n 'loadend',\n 'load',\n 'timeout',\n 'abort',\n ]\n\n /**\n * `ProgressEvent` is not supported in React Native.\n * @see https://github.com/mswjs/interceptors/issues/40\n */\n const ProgressEventClass = SUPPORTS_PROGRESS_EVENT\n ? ProgressEvent\n : ProgressEventPolyfill\n\n const event = progressEvents.includes(type)\n ? new ProgressEventClass(type, {\n lengthComputable: true,\n loaded: init?.loaded || 0,\n total: init?.total || 0,\n })\n : new EventPolyfill(type, {\n target,\n currentTarget: target,\n })\n\n return event\n}\n","/**\n * Returns the source object of the given property on the target object\n * (the target itself, any parent in its prototype, or null).\n */\nexport function findPropertySource(\n target: object,\n propertyName: string | symbol\n): object | null {\n if (!(propertyName in target)) {\n return null\n }\n\n const hasProperty = Object.prototype.hasOwnProperty.call(target, propertyName)\n if (hasProperty) {\n return target\n }\n\n const prototype = Reflect.getPrototypeOf(target)\n return prototype ? findPropertySource(prototype, propertyName) : null\n}\n","import { findPropertySource } from './find-property-source'\n\nexport interface ProxyOptions<Target extends Record<string, any>> {\n constructorCall?(args: Array<unknown>, next: NextFunction<Target>): Target\n\n methodCall?<F extends keyof Target>(\n this: Target,\n data: [methodName: F, args: Array<unknown>],\n next: NextFunction<void>\n ): void\n\n setProperty?(\n data: [propertyName: string | symbol, nextValue: unknown],\n next: NextFunction<boolean>\n ): boolean\n\n getProperty?(\n data: [propertyName: string | symbol, receiver: Target],\n next: NextFunction<void>\n ): void\n}\n\nexport type NextFunction<ReturnType> = () => ReturnType\n\nexport function createProxy<Target extends object>(\n target: Target,\n options: ProxyOptions<Target>\n): Target {\n const proxy = new Proxy(target, optionsToProxyHandler(options))\n\n return proxy\n}\n\nfunction optionsToProxyHandler<T extends Record<string, any>>(\n options: ProxyOptions<T>\n): ProxyHandler<T> {\n const { constructorCall, methodCall, getProperty, setProperty } = options\n const handler: ProxyHandler<T> = {}\n\n if (typeof constructorCall !== 'undefined') {\n handler.construct = function (target, args, newTarget) {\n const next = Reflect.construct.bind(null, target as any, args, newTarget)\n return constructorCall.call(newTarget, args, next)\n }\n }\n\n handler.set = function (target, propertyName, nextValue) {\n const next = () => {\n const propertySource = findPropertySource(target, propertyName) || target\n const ownDescriptors = Reflect.getOwnPropertyDescriptor(\n propertySource,\n propertyName\n )\n\n // Respect any custom setters present for this property.\n if (typeof ownDescriptors?.set !== 'undefined') {\n ownDescriptors.set.apply(target, [nextValue])\n return true\n }\n\n // Otherwise, set the property on the source.\n return Reflect.defineProperty(propertySource, propertyName, {\n writable: true,\n enumerable: true,\n configurable: true,\n value: nextValue,\n })\n }\n\n if (typeof setProperty !== 'undefined') {\n return setProperty.call(target, [propertyName, nextValue], next)\n }\n\n return next()\n }\n\n handler.get = function (target, propertyName, receiver) {\n /**\n * @note Using `Reflect.get()` here causes \"TypeError: Illegal invocation\".\n */\n const next = () => target[propertyName as any]\n\n const value =\n typeof getProperty !== 'undefined'\n ? getProperty.call(target, [propertyName, receiver], next)\n : next()\n\n if (typeof value === 'function') {\n return (...args: Array<any>) => {\n const next = value.bind(target, ...args)\n\n if (typeof methodCall !== 'undefined') {\n return methodCall.call(target, [propertyName as any, args], next)\n }\n\n return next()\n }\n }\n\n return value\n }\n\n return handler\n}\n","export function isDomParserSupportedType(\n type: string\n): type is DOMParserSupportedType {\n const supportedTypes: Array<DOMParserSupportedType> = [\n 'application/xhtml+xml',\n 'application/xml',\n 'image/svg+xml',\n 'text/html',\n 'text/xml',\n ]\n return supportedTypes.some((supportedType) => {\n return type.startsWith(supportedType)\n })\n}\n","/**\n * Parses a given string into JSON.\n * Gracefully handles invalid JSON by returning `null`.\n */\nexport function parseJson(data: string): Record<string, unknown> | null {\n try {\n const json = JSON.parse(data)\n return json\n } catch (_) {\n return null\n }\n}\n","import { FetchResponse } from '../../../utils/fetch-utils'\n\n/**\n * Creates a Fetch API `Response` instance from the given\n * `XMLHttpRequest` instance and a response body.\n */\nexport function createResponse(\n request: XMLHttpRequest,\n body: BodyInit | null\n): Response {\n /**\n * Handle XMLHttpRequest responses that must have null as the\n * response body when represented using Fetch API Response.\n * XMLHttpRequest response will always have an empty string\n * as the \"request.response\" in those cases, resulting in an error\n * when constructing a Response instance.\n * @see https://github.com/mswjs/interceptors/issues/379\n */\n const responseBodyOrNull = FetchResponse.isResponseWithBody(request.status)\n ? body\n : null\n\n return new FetchResponse(responseBodyOrNull, {\n url: request.responseURL,\n status: request.status,\n statusText: request.statusText,\n headers: createHeadersFromXMLHttpRequestHeaders(\n request.getAllResponseHeaders()\n ),\n })\n}\n\nfunction createHeadersFromXMLHttpRequestHeaders(headersString: string): Headers {\n const headers = new Headers()\n\n const lines = headersString.split(/[\\r\\n]+/)\n for (const line of lines) {\n if (line.trim() === '') {\n continue\n }\n\n const [name, ...parts] = line.split(': ')\n const value = parts.join(': ')\n\n headers.append(name, value)\n }\n\n return headers\n}\n","/**\n * Return a total byte length of the given request/response body.\n * If the `Content-Length` header is present, it will be used as the byte length.\n */\nexport async function getBodyByteLength(\n input: Request | Response\n): Promise<number> {\n const explicitContentLength = input.headers.get('content-length')\n\n if (explicitContentLength != null && explicitContentLength !== '') {\n return Number(explicitContentLength)\n }\n\n const buffer = await input.arrayBuffer()\n return buffer.byteLength\n}\n","import { until } from '@open-draft/until'\nimport { invariant } from 'outvariant'\nimport type { Logger } from '../../utils/logger'\nimport type { HttpResponseType } from '../../events/http'\nimport { concatArrayBuffer } from './utils/concat-array-buffer'\nimport { createEvent } from './utils/create-event'\nimport {\n decodeBuffer,\n encodeBuffer,\n toArrayBuffer,\n} from '../../utils/buffer-utils'\nimport { createProxy } from '../../utils/create-proxy'\nimport { isDomParserSupportedType } from './utils/is-dom-parser-supported-type'\nimport { parseJson } from '../../utils/parse-json'\nimport { createResponse } from './utils/create-response'\nimport { createRequestId } from '../../create-request-id'\nimport { getBodyByteLength } from './utils/get-body-byte-length'\nimport { FetchRequest, FetchResponse } from '../../utils/fetch-utils'\nimport { isResponseError } from '../../utils/response-utils'\n\nconst kIsRequestHandled = Symbol('kIsRequestHandled')\nconst kFetchRequest = Symbol('kFetchRequest')\nconst MAX_REDIRECTS = 20\n\n/**\n * An `XMLHttpRequest` instance controller that allows us\n * to handle any given request instance (e.g. responding to it).\n */\nexport class XMLHttpRequestController {\n public request: XMLHttpRequest\n public requestId: string\n public onRequest?: (\n this: XMLHttpRequestController,\n args: {\n request: Request\n requestId: string\n }\n ) => Promise<void>\n public onResponse?: (\n this: XMLHttpRequestController,\n args: {\n response: Response\n responseType: HttpResponseType\n request: Request\n requestId: string\n }\n ) => void;\n\n [kIsRequestHandled]: boolean;\n [kFetchRequest]?: Request\n\n private sync: boolean = false\n private method: string = 'GET'\n private url: URL = null as any\n private requestHeaders: Headers\n private responseBuffer: Uint8Array<ArrayBuffer>\n private redirectCount: number\n private events: Map<keyof XMLHttpRequestEventTargetEventMap, Array<Function>>\n private uploadEvents: Map<\n keyof XMLHttpRequestEventTargetEventMap,\n Array<Function>\n >\n\n constructor(\n readonly initialRequest: XMLHttpRequest,\n public logger: Logger\n ) {\n this[kIsRequestHandled] = false\n\n this.redirectCount = 0\n this.events = new Map()\n this.uploadEvents = new Map()\n this.requestId = createRequestId()\n this.requestHeaders = new Headers()\n this.responseBuffer = new Uint8Array()\n\n this.request = createProxy(initialRequest, {\n methodCall: ([methodName, args], invoke) => {\n switch (methodName) {\n case 'open': {\n const [method, url, async] = args as [\n string,\n string | undefined,\n boolean | undefined,\n ]\n\n this.sync = !(async ?? true)\n\n if (typeof url === 'undefined') {\n this.method = 'GET'\n this.url = toAbsoluteUrl(method)\n } else {\n this.method = method\n this.url = toAbsoluteUrl(url)\n }\n\n this.logger.verbose('open %s %s', this.method, this.url.href)\n\n return invoke()\n }\n\n case 'addEventListener': {\n const [eventName, listener] = args as [\n keyof XMLHttpRequestEventTargetEventMap,\n Function,\n ]\n\n this.registerEvent(eventName, listener)\n this.logger.verbose('addEventListener', eventName, listener)\n\n return invoke()\n }\n\n case 'setRequestHeader': {\n const [name, value] = args as [string, string]\n this.requestHeaders.set(name, value)\n\n this.logger.verbose('setRequestHeader', name, value)\n\n return invoke()\n }\n\n case 'send': {\n const [body] = args as [\n body?: XMLHttpRequestBodyInit | Document | null,\n ]\n\n if (this.sync) {\n console.warn(\n `Failed to intercept an XMLHttpRequest (${this.method} ${this.url}): synchronous requests are not supported. This request will be performed as-is.`\n )\n return invoke()\n }\n\n this.request.addEventListener('load', () => {\n if (typeof this.onResponse !== 'undefined') {\n // Create a Fetch API Response representation of whichever\n // response this XMLHttpRequest received. Note those may\n // be either a mocked and the original response.\n const fetchResponse = createResponse(\n this.request,\n /**\n * The `response` property is the right way to read\n * the ambiguous response body, as the request's \"responseType\" may differ.\n * @see https://xhr.spec.whatwg.org/#the-response-attribute\n */\n this.request.response\n )\n\n // Notify the consumer about the response.\n this.onResponse.call(this, {\n response: fetchResponse,\n responseType: this[kIsRequestHandled] ? 'mock' : 'original',\n request: fetchRequest,\n requestId: this.requestId!,\n })\n }\n })\n\n const requestBody =\n typeof body === 'string' ? encodeBuffer(body) : body\n\n // Delegate request handling to the consumer.\n const fetchRequest = this.toFetchApiRequest(requestBody)\n this[kFetchRequest] = fetchRequest.clone()\n\n /**\n * @note Start request handling on the next tick so that the user\n * could add event listeners for \"loadend\" before the interceptor fires it.\n */\n queueMicrotask(() => {\n const onceRequestSettled =\n this.onRequest?.call(this, {\n request: fetchRequest,\n requestId: this.requestId!,\n }) || Promise.resolve()\n\n onceRequestSettled.finally(() => {\n // If the consumer didn't handle the request (called `.respondWith()`) perform it as-is.\n if (!this[kIsRequestHandled]) {\n this.logger.verbose(\n 'request callback settled but request has not been handled (readystate %d), performing as-is...',\n this.request.readyState\n )\n\n return invoke()\n }\n })\n })\n\n break\n }\n\n default: {\n return invoke()\n }\n }\n },\n })\n\n /**\n * Proxy the `.upload` property to gather the event listeners/callbacks.\n */\n define(\n this.request,\n 'upload',\n createProxy(this.request.upload, {\n setProperty: ([propertyName, nextValue], invoke) => {\n switch (propertyName) {\n case 'onloadstart':\n case 'onprogress':\n case 'onaboart':\n case 'onerror':\n case 'onload':\n case 'ontimeout':\n case 'onloadend': {\n const eventName = propertyName.slice(\n 2\n ) as keyof XMLHttpRequestEventTargetEventMap\n\n this.registerUploadEvent(eventName, nextValue as Function)\n }\n }\n\n return invoke()\n },\n methodCall: ([methodName, args], invoke) => {\n switch (methodName) {\n case 'addEventListener': {\n const [eventName, listener] = args as [\n keyof XMLHttpRequestEventTargetEventMap,\n Function,\n ]\n this.registerUploadEvent(eventName, listener)\n this.logger.verbose('upload.addEventListener', eventName, listener)\n\n return invoke()\n }\n }\n },\n })\n )\n }\n\n private registerEvent(\n eventName: keyof XMLHttpRequestEventTargetEventMap,\n listener: Function\n ): void {\n const prevEvents = this.events.get(eventName) || []\n const nextEvents = prevEvents.concat(listener)\n this.events.set(eventName, nextEvents)\n\n this.logger.verbose('registered event \"%s\"', eventName, listener)\n }\n\n private registerUploadEvent(\n eventName: keyof XMLHttpRequestEventTargetEventMap,\n listener: Function\n ): void {\n const prevEvents = this.uploadEvents.get(eventName) || []\n const nextEvents = prevEvents.concat(listener)\n this.uploadEvents.set(eventName, nextEvents)\n\n this.logger.verbose('registered upload event \"%s\"', eventName, listener)\n }\n\n /**\n * Responds to the current request with the given\n * Fetch API `Response` instance.\n */\n public async respondWith(response: Response): Promise<void> {\n /**\n * @note Since `XMLHttpRequestController` delegates the handling of the responses\n * to the \"load\" event listener that doesn't distinguish between the mocked and original\n * responses, mark the request that had a mocked response with a corresponding symbol.\n *\n * Mark this request as having a mocked response immediately since\n * calculating request/response total body length is asynchronous.\n */\n this[kIsRequestHandled] = true\n\n this.logger.verbose(\n 'responding with a mocked response: %d %s',\n response.status,\n response.statusText\n )\n\n FetchResponse.setUrl(this.url.href, response)\n\n // Update the response getters to resolve against the mocked response.\n Object.defineProperties(this.request, {\n response: {\n enumerable: true,\n configurable: false,\n get: () => this.response,\n },\n responseText: {\n enumerable: true,\n configurable: false,\n get: () => this.responseText,\n },\n responseXML: {\n enumerable: true,\n configurable: false,\n get: () => this.responseXML,\n },\n })\n\n // 1. Fire a progress event named loadstart at this with 0 and 0.\n this.trigger('loadstart', this.request, { loaded: 0, total: 0 })\n\n // 2. Let requestBodyTransmitted be 0.\n let requestBodyTransmitted = 0\n let uploadComplete = false\n\n if (this[kFetchRequest]) {\n const requestBodyLength = await getBodyByteLength(\n this[kFetchRequest].clone()\n )\n\n // 5. If this’s upload complete flag is unset and this’s upload listener flag is set, then fire a progress event named loadstart at this’s upload object with requestBodyTransmitted and requestBodyLength.\n if (!uploadComplete) {\n this.trigger('loadstart', this.request.upload, {\n loaded: 0,\n total: requestBodyLength,\n })\n }\n\n const processRequestBodyChunkLength = (bytesLength: number) => {\n requestBodyTransmitted += bytesLength\n\n if (requestBodyTransmitted < requestBodyLength) {\n this.trigger('progress', this.request.upload, {\n loaded: requestBodyTransmitted,\n total: requestBodyLength,\n })\n }\n }\n\n const processRequestEndOfBody = () => {\n uploadComplete = true\n\n this.trigger('progress', this.request.upload, {\n loaded: requestBodyTransmitted,\n total: requestBodyLength,\n })\n this.trigger('load', this.request.upload, {\n loaded: requestBodyTransmitted,\n total: requestBodyLength,\n })\n this.trigger('loadend', this.request.upload, {\n loaded: requestBodyTransmitted,\n total: requestBodyLength,\n })\n }\n\n if (this[kFetchRequest]?.body != null) {\n const reader = this[kFetchRequest].body.getReader()\n\n while (true) {\n const { value, done } = await reader.read()\n\n if (done) {\n processRequestEndOfBody()\n break\n }\n\n processRequestBodyChunkLength(value.byteLength)\n }\n } else {\n processRequestEndOfBody()\n }\n }\n\n let timedOut = false\n const responseReadController = new AbortController()\n\n const requestErrorSteps = (\n event: keyof XMLHttpRequestEventTargetEventMap\n ) => {\n this.setReadyState(this.request.DONE)\n\n if (!uploadComplete) {\n this.trigger(event, this.request.upload, {\n loaded: 0,\n total: 0,\n })\n this.trigger('loadend', this.request.upload, {\n loaded: 0,\n total: 0,\n })\n }\n\n this.trigger(event, this.request, { loaded: 0, total: 0 })\n this.trigger('loadend', this.request, { loaded: 0, total: 0 })\n }\n\n const processResponse = async (response: Response) => {\n const handleErrors = () => {\n if (timedOut) {\n requestErrorSteps('timeout')\n } else if (responseReadController.signal.aborted) {\n requestErrorSteps('abort')\n } else if (isResponseError(response)) {\n requestErrorSteps('error')\n }\n }\n\n handleErrors()\n\n define(this.request, 'status', response.status)\n define(this.request, 'statusText', response.statusText)\n\n if (!this.request.responseURL) {\n define(this.request, 'responseURL', response.url)\n }\n\n if (isResponseError(response)) {\n return\n }\n\n /**\n * @note The response body length is derived ONLY from the \"content-length\" header.\n * If that response header is not set, the \"total\" in all progress events must be 0.\n */\n const responseBodyLength = Number(\n response.headers.get('content-length') ?? '0'\n )\n\n this.setReadyState(this.request.HEADERS_RECEIVED)\n\n let receivedBytes = 0\n let lastReceivedResponseBytesAt = performance.now()\n\n const processResponseBodyChunk = (bytesLength: number) => {\n receivedBytes += bytesLength\n\n const now = performance.now()\n const shouldBuffer =\n now - lastReceivedResponseBytesAt <= 60 &&\n receivedBytes < responseBodyLength\n lastReceivedResponseBytesAt = now\n\n if (shouldBuffer) {\n return\n }\n\n if (this.request.readyState === this.request.HEADERS_RECEIVED) {\n this.setReadyState(this.request.LOADING, false)\n }\n\n this.trigger('readystatechange', this.request)\n this.trigger('progress', this.request, {\n loaded: receivedBytes,\n total: responseBodyLength,\n })\n }\n\n const processResponseBodyError = () => {\n requestErrorSteps('error')\n }\n\n const processResponseEndOfBody = async () => {\n handleErrors()\n\n if (isResponseError(response)) {\n return\n }\n\n // 3. Let transmitted be xhr’s received bytes’s length.\n let transmitted = receivedBytes\n\n // 9. Fire an event named readystatechange at xhr.\n this.setReadyState(this.request.DONE)\n // 10. Fire a progress event named load at xhr with transmitted and length.\n this.trigger('load', this.request, {\n loaded: transmitted,\n total: responseBodyLength,\n })\n // 11. Fire a progress event named loadend at xhr with transmitted and length.\n this.trigger('loadend', this.request, {\n loaded: transmitted,\n total: responseBodyLength,\n })\n }\n\n // 7. If this’s response’s body is null, then run handle response end-of-body for this and return.\n if (response.body == null) {\n processResponseEndOfBody()\n } else {\n const reader = response.body.getReader()\n\n while (true) {\n if (responseReadController.signal.aborted) {\n break\n }\n\n try {\n const { value, done } = await reader.read()\n\n if (done) {\n processResponseEndOfBody()\n return\n }\n\n processResponseBodyChunk(value.byteLength)\n this.responseBuffer = concatArrayBuffer(this.responseBuffer, value)\n } catch {\n processResponseBodyError()\n }\n }\n }\n }\n\n // Redirects are followed as a part of the fetch controller. Since we don't have one,\n // retrieve the final response and then continue with processing it instead of the mocked one.\n const [redirectError, finalResponse] = await until(() => {\n return this.followRedirects(response)\n })\n\n if (redirectError) {\n return\n }\n\n processResponse(finalResponse)\n\n // 12.1, 12.2.\n if (this.request.timeout) {\n setTimeout(() => {\n if (this.request.readyState !== this.request.DONE) {\n timedOut = true\n responseReadController.abort()\n }\n }, this.request.timeout)\n }\n\n this.request.getResponseHeader = new Proxy(this.request.getResponseHeader, {\n apply: (_, __, args: [name: string]) => {\n this.logger.verbose('getResponseHeader', args[0])\n\n if (this.request.readyState < this.request.HEADERS_RECEIVED) {\n this.logger.verbose('headers not received yet, returning null')\n return null\n }\n\n const headerValue = finalResponse.headers.get(args[0])\n this.logger.verbose(\n 'resolved response header \"%s\" to',\n args[0],\n headerValue\n )\n\n return headerValue\n },\n })\n\n this.request.getAllResponseHeaders = new Proxy(\n this.request.getAllResponseHeaders,\n {\n apply: () => {\n this.logger.verbose('getAllResponseHeaders')\n\n if (this.request.readyState < this.request.HEADERS_RECEIVED) {\n this.logger.verbose('headers not received yet, returning empty string')\n return ''\n }\n\n const headersList = Array.from(finalResponse.headers)\n const allHeaders = headersList\n .map(([headerName, headerValue]) => {\n return `${headerName}: ${headerValue}`\n })\n .join('\\r\\n')\n\n this.logger.verbose('resolved all response headers to', allHeaders)\n\n return allHeaders\n },\n }\n )\n }\n\n private responseBufferToText(): string {\n return decodeBuffer(this.responseBuffer)\n }\n\n get response(): unknown {\n this.logger.verbose(\n 'getResponse (responseType: %s)',\n this.request.responseType\n )\n\n if (this.request.readyState !== this.request.DONE) {\n return null\n }\n\n switch (this.request.responseType) {\n case 'json': {\n const responseJson = parseJson(this.responseBufferToText())\n this.logger.verbose('resolved response JSON', responseJson)\n\n return responseJson\n }\n\n case 'arraybuffer': {\n const arrayBuffer = toArrayBuffer(this.responseBuffer)\n this.logger.verbose('resolved response ArrayBuffer', arrayBuffer)\n\n return arrayBuffer\n }\n\n case 'blob': {\n const mimeType =\n this.request.getResponseHeader('Content-Type') || 'text/plain'\n const responseBlob = new Blob([this.responseBufferToText()], {\n type: mimeType,\n })\n\n this.logger.verbose(\n 'resolved response Blob (mime type: %s)',\n responseBlob,\n mimeType\n )\n\n return responseBlob\n }\n\n default: {\n const responseText = this.responseBufferToText()\n this.logger.verbose(\n 'resolving \"%s\" response type as text',\n this.request.responseType,\n responseText\n )\n\n return responseText\n }\n }\n }\n\n get responseText(): string {\n /**\n * Throw when trying to read the response body as text when the\n * \"responseType\" doesn't expect text. This just respects the spec better.\n * @see https://xhr.spec.whatwg.org/#the-responsetext-attribute\n */\n invariant(\n this.request.responseType === '' || this.request.responseType === 'text',\n 'InvalidStateError: The object is in invalid state.'\n )\n\n if (\n this.request.readyState !== this.request.LOADING &&\n this.request.readyState !== this.request.DONE\n ) {\n return ''\n }\n\n const responseText = this.responseBufferToText()\n this.logger.verbose('getResponseText: \"%s\"', responseText)\n\n return responseText\n }\n\n get responseXML(): Document | null {\n invariant(\n this.request.responseType === '' ||\n this.request.responseType === 'document',\n 'InvalidStateError: The object is in invalid state.'\n )\n\n if (this.request.readyState !== this.request.DONE) {\n return null\n }\n\n const contentType = this.request.getResponseHeader('Content-Type') || ''\n\n if (typeof DOMParser === 'undefined') {\n console.warn(\n 'Cannot retrieve XMLHttpRequest response body as XML: DOMParser is not defined. You are likely using an environment that is not browser or does not polyfill browser globals correctly.'\n )\n return null\n }\n\n if (isDomParserSupportedType(contentType)) {\n return new DOMParser().parseFromString(\n this.responseBufferToText(),\n contentType\n )\n }\n\n return null\n }\n\n private async followRedirects(response: Response): Promise<Response> {\n const redirectLocation = response.headers.get('location')\n\n if (\n !redirectLocation ||\n !FetchResponse.isRedirectResponse(response.status)\n ) {\n return response\n }\n\n this.redirectCount++\n\n if (this.redirectCount > MAX_REDIRECTS) {\n throw new Error('Too many redirects')\n }\n\n const redirectUrl = new URL(redirectLocation, location.href)\n const redirectMethod = FetchResponse.isResponseWithBody(response.status)\n ? this.method\n : 'GET'\n\n const redirectResponse = await new Promise<Response>((resolve, reject) => {\n const request = new XMLHttpRequest()\n request.responseType = this.request.responseType\n\n request.addEventListener('load', () => {\n this.url = new URL(request.responseURL)\n resolve(createResponse(request, request.response))\n })\n\n request.addEventListener('error', () => {\n this.errorWith()\n reject(new Error('Redirect request failed'))\n })\n\n request.open(redirectMethod, redirectUrl.href)\n request.send()\n })\n\n return this.followRedirects(redirectResponse)\n }\n\n public errorWith(error?: Error): void {\n /**\n * @note Mark this request as handled even if it received a mock error.\n * This prevents the controller from trying to perform this request as-is.\n */\n this[kIsRequestHandled] = true\n this.logger.verbose('responding with an error')\n\n this.setReadyState(this.request.DONE)\n this.trigger('error', this.request)\n this.trigger('loadend', this.request)\n }\n\n /**\n * Transitions this request's `readyState` to the given one.\n */\n private setReadyState(\n nextReadyState: number,\n triggerReadyStateChangeEvent = true\n ): void {\n this.logger.verbose(\n 'setReadyState: %d -> %d',\n this.request.readyState,\n nextReadyState\n )\n\n if (this.request.readyState === nextReadyState) {\n this.logger.verbose('ready state identical, skipping transition...')\n return\n }\n\n define(this.request, 'readyState', nextReadyState)\n\n this.logger.verbose('set readyState to: %d', nextReadyState)\n\n if (!triggerReadyStateChangeEvent) {\n return\n }\n\n if (nextReadyState !== this.request.UNSENT) {\n this.logger.verbose('triggering \"readystatechange\" event...')\n\n this.trigger('readystatechange', this.request)\n }\n }\n\n /**\n * Triggers given event on the `XMLHttpRequest` instance.\n */\n private trigger<\n EventName extends keyof (XMLHttpRequestEventTargetEventMap & {\n readystatechange: ProgressEvent<XMLHttpRequestEventTarget>\n }),\n >(\n eventName: EventName,\n target: XMLHttpRequest | XMLHttpRequestUpload,\n options?: ProgressEventInit\n ): void {\n const callback = (target as XMLHttpRequest)[`on${eventName}`]\n const event = createEvent(target, eventName, options)\n\n this.logger.verbose('trigger \"%s\"', eventName, options || '')\n\n // Invoke direct callbacks.\n if (typeof callback === 'function') {\n this.logger.verbose('found a direct \"%s\" callback, calling...', eventName)\n callback.call(target as XMLHttpRequest, event)\n }\n\n // Invoke event listeners.\n const events =\n target instanceof XMLHttpRequestUpload ? this.uploadEvents : this.events\n\n for (const [registeredEventName, listeners] of events) {\n if (registeredEventName === eventName) {\n this.logger.verbose(\n 'found %d listener(s) for \"%s\" event, calling...',\n listeners.length,\n eventName\n )\n\n listeners.forEach((listener) => listener.call(target, event))\n }\n }\n }\n\n /**\n * Converts this `XMLHttpRequest` instance into a Fetch API `Request` instance.\n */\n private toFetchApiRequest(\n body: XMLHttpRequestBodyInit | Document | null | undefined\n ): Request {\n this.logger.verbose('converting request to a Fetch API Request...')\n\n // If the `Document` is used as the body of this XMLHttpRequest,\n // set its inner text as the Fetch API Request body.\n const resolvedBody =\n body instanceof Document ? body.documentElement.innerText : body\n\n const fetchRequest = new FetchRequest(this.url.href, {\n method: this.method,\n headers: this.requestHeaders,\n /**\n * @see https://xhr.spec.whatwg.org/#cross-origin-credentials\n */\n credentials: this.request.withCredentials ? 'include' : 'same-origin',\n body: resolvedBody,\n })\n\n const headers = fetchRequest.headers\n const proxyHeaders = createProxy(headers, {\n methodCall: ([methodName, args], invoke) => {\n const result = invoke()\n\n // Forward the latest state of the internal request headers\n // because the interceptor might have modified them\n // without responding to the request.\n switch (methodName) {\n case 'append':\n case 'set': {\n const [headerName, headerValue] = args as [string, string]\n\n /**\n * @note Forward only the headers the Fetch API Request accepted.\n * Forbidden request headers (e.g. \"Cookie\") are dropped silently\n * by the request's headers guard, and forwarding them makes\n * the browser refuse them with an error in the console.\n */\n if (headers.has(headerName)) {\n this.request.setRequestHeader(headerName, headerValue)\n }\n break\n }\n\n case 'delete': {\n const [headerName] = args as [string]\n console.warn(\n `XMLHttpRequest: Cannot remove a \"${headerName}\" header from the Fetch API representation of the \"${fetchRequest.method} ${fetchRequest.url}\" request. XMLHttpRequest headers cannot be removed.`\n )\n break\n }\n }\n\n return result\n },\n })\n define(fetchRequest, 'headers', proxyHeaders)\n // setRawRequest(fetchRequest, this.request)\n\n this.logger.verbose('converted request to a Fetch API Request!', fetchRequest)\n\n return fetchRequest\n }\n}\n\nfunction toAbsoluteUrl(url: string | URL): URL {\n /**\n * @note XMLHttpRequest interceptor may run in environments\n * that implement XMLHttpRequest but don't implement \"location\"\n * (for example, React Native). If that's the case, return the\n * input URL as-is (nothing to be relative to).\n * @see https://github.com/mswjs/msw/issues/1777\n */\n if (typeof location === 'undefined') {\n return new URL(url)\n }\n\n return new URL(url.toString(), location.href)\n}\n\nfunction define(\n target: object,\n property: string | symbol,\n value: unknown\n): void {\n Reflect.defineProperty(target, property, {\n // Ensure writable properties to allow redefining readonly properties.\n writable: true,\n enumerable: true,\n value,\n })\n}\n","import type { Emitter } from 'rettime'\nimport { HttpResponseEvent, type HttpRequestEventMap } from '../../events/http'\nimport { RequestController } from '../../request-controller'\nimport { XMLHttpRequestController } from './xml-http-request-controller'\nimport { handleRequest } from '../../utils/handle-request'\nimport type { Logger } from '../../utils/logger'\n\nexport interface XMLHttpRequestProxyOptions {\n emitter: Emitter<HttpRequestEventMap>\n logger: Logger\n}\n\n/**\n * Create a proxied `XMLHttpRequest` class.\n * The proxied class establishes spies on certain methods,\n * allowing us to intercept requests and respond to them.\n */\nexport function createXMLHttpRequestProxy({\n emitter,\n logger,\n}: XMLHttpRequestProxyOptions) {\n const XMLHttpRequestProxy = new Proxy(globalThis.XMLHttpRequest, {\n construct(target, args, newTarget) {\n logger.verbose('constructed new XMLHttpRequest')\n\n const originalRequest = Reflect.construct(\n target,\n args,\n newTarget\n ) as XMLHttpRequest\n\n /**\n * @note Forward prototype descriptors onto the proxied object.\n * XMLHttpRequest is implemented in JSDOM in a way that assigns\n * a bunch of descriptors, like \"set responseType()\" on the prototype.\n * With this propagation, we make sure that those descriptors trigger\n * when the user operates with the proxied request instance.\n */\n const prototypeDescriptors = Object.getOwnPropertyDescriptors(\n target.prototype\n )\n for (const propertyName in prototypeDescriptors) {\n Reflect.defineProperty(\n originalRequest,\n propertyName,\n prototypeDescriptors[propertyName]\n )\n }\n\n const xhrRequestController = new XMLHttpRequestController(\n originalRequest,\n logger\n )\n\n xhrRequestController.onRequest = async function ({ request, requestId }) {\n const controller = new RequestController(request, {\n passthrough: () => {\n this.logger.verbose(\n 'no mocked response received, performing request as-is...'\n )\n },\n respondWith: async (response) => {\n await this.respondWith(response)\n },\n errorWith: (reason) => {\n this.logger.verbose('request errored %o', { error: reason })\n\n if (reason instanceof Error) {\n this.errorWith(reason)\n }\n },\n }, {\n logger,\n requestId,\n })\n\n this.logger.verbose('awaiting mocked response')\n\n this.logger.verbose(\n 'emitting the \"request\" event for %s listener(s)...',\n emitter.listenerCount('request')\n )\n\n await handleRequest({\n initiator: this.request,\n request,\n requestId,\n controller,\n emitter,\n logger,\n })\n }\n\n xhrRequestController.onResponse = async function ({\n response,\n responseType,\n request,\n requestId,\n }) {\n this.logger.verbose(\n 'emitting the \"response\" event for %s listener(s)...',\n emitter.listenerCount('response')\n )\n\n await emitter.emitAsPromise(\n new HttpResponseEvent({\n initiator: this.request,\n response,\n responseType,\n request,\n requestId,\n })\n )\n }\n\n // Return the proxied request from the controller\n // so that the controller can react to the consumer's interactions\n // with this request (opening/sending/etc).\n return xhrRequestController.request\n },\n })\n\n return XMLHttpRequestProxy\n}\n","import { HttpRequestEventMap } from '../../events/http'\nimport { Interceptor } from '../../interceptor'\nimport { createXMLHttpRequestProxy } from './xml-http-request-proxy'\nimport { hasConfigurableGlobal } from '../../utils/has-configurable-global'\nimport { patchesRegistry } from '../../utils/patches-registry'\nimport { createLogger } from '../../utils/logger'\n\nconst logger = createLogger('xhr')\n\nexport class XMLHttpRequestInterceptor extends Interceptor<HttpRequestEventMap> {\n static symbol = Symbol.for('xhr-interceptor')\n\n protected predicate() {\n return hasConfigurableGlobal('XMLHttpRequest')\n }\n\n protected setup() {\n logger.verbose('patching \"XMLHttpRequest\"...')\n\n this.subscriptions.push(\n patchesRegistry.applyPatch(globalThis, 'XMLHttpRequest', () => {\n return createXMLHttpRequestProxy({\n emitter: this.emitter,\n logger,\n })\n })\n )\n\n logger.verbose(\n 'global \"XMLHttpRequest\" patched!',\n globalThis.XMLHttpRequest.name\n )\n }\n}\n"],"mappings":";;;;;;;;;;;AAGA,SAAgB,kBACd,MACA,OACA;CACA,MAAM,SAAS,IAAI,WAAW,KAAK,aAAa,MAAM,UAAU;CAChE,OAAO,IAAI,MAAM,CAAC;CAClB,OAAO,IAAI,OAAO,KAAK,UAAU;CACjC,OAAO;AACT;;;ACXA,IAAa,gBAAb,MAA4C;CAwB1C,YACE,MACA,SACA;EA1Bc,KAAA,OAAA;EACW,KAAA,kBAAA;EACN,KAAA,YAAA;EACK,KAAA,iBAAA;EAEJ,KAAA,OAAA;EACkB,KAAA,aAAA;EAEG,KAAA,gBAAA;EACf,KAAA,aAAA;EAEA,KAAA,YAAA;EACD,KAAA,WAAA;EACE,KAAA,aAAA;EACM,KAAA,mBAAA;EACT,KAAA,UAAA;EACS,KAAA,mBAAA;EACX,KAAA,SAAA;EACD,KAAA,QAAA;EAEC,KAAA,eAAA;EACD,KAAA,cAAA;EAMrB,KAAK,OAAO;EACZ,KAAK,SAAS,SAAS,UAAU;EACjC,KAAK,gBAAgB,SAAS,iBAAiB;EAC/C,KAAK,YAAY,KAAK,IAAI;CAC5B;CAEA,eAAqC;EACnC,OAAO,CAAC;CACV;CAEA,UAAiB,MAAc,SAAmB,YAAsB;EACtE,KAAK,OAAO;EACZ,KAAK,UAAU,CAAC,CAAC;EACjB,KAAK,aAAa,CAAC,CAAC;CACtB;CAEA,iBAAwB;EACtB,KAAK,mBAAmB;CAC1B;CAEA,kBAAyB,CAAC;CAC1B,2BAAkC,CAAC;AACrC;;;AChDA,IAAa,wBAAb,cAA2C,cAAc;CAMvD,YAAY,MA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,MAAM,SAAS,aAAa,KAAK;AAEjC,IAAa,4BAAb,cAA+C,YAAiC;;EAC9D,KAAA,SAAA,OAAO,IAAI,iBAAiB;;CAE5C,YAAsB;EACpB,OAAO,sBAAsB,gBAAgB;CAC/C;CAEA,QAAkB;EAChB,OAAO,QAAQ,gCAA8B;EAE7C,KAAK,cAAc,KACjB,gBAAgB,WAAW,YAAY,wBAAwB;GAC7D,OAAO,0BAA0B;IAC/B,SAAS,KAAK;IACd;GACF,CAAC;EACH,CAAC,CACH;EAEA,OAAO,QACL,sCACA,WAAW,eAAe,IAC5B;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@depup/mswjs__interceptors",
|
|
4
4
|
"description": "Low-level network interception library for Node.js. (with updated dependencies)",
|
|
5
|
-
"version": "0.43.
|
|
5
|
+
"version": "0.43.1-depup.0",
|
|
6
6
|
"main": "./lib/node/index.js",
|
|
7
7
|
"types": "./lib/node/index.d.ts",
|
|
8
8
|
"exports": {
|
|
@@ -159,8 +159,8 @@
|
|
|
159
159
|
"changes": {},
|
|
160
160
|
"depsUpdated": 0,
|
|
161
161
|
"originalPackage": "@mswjs/interceptors",
|
|
162
|
-
"originalVersion": "0.43.
|
|
163
|
-
"processedAt": "2026-09-
|
|
162
|
+
"originalVersion": "0.43.1",
|
|
163
|
+
"processedAt": "2026-09-18T08:11:27.626Z",
|
|
164
164
|
"smokeTest": "passed"
|
|
165
165
|
}
|
|
166
166
|
}
|
|
@@ -843,8 +843,11 @@ export class XMLHttpRequestController {
|
|
|
843
843
|
body: resolvedBody,
|
|
844
844
|
})
|
|
845
845
|
|
|
846
|
-
const
|
|
846
|
+
const headers = fetchRequest.headers
|
|
847
|
+
const proxyHeaders = createProxy(headers, {
|
|
847
848
|
methodCall: ([methodName, args], invoke) => {
|
|
849
|
+
const result = invoke()
|
|
850
|
+
|
|
848
851
|
// Forward the latest state of the internal request headers
|
|
849
852
|
// because the interceptor might have modified them
|
|
850
853
|
// without responding to the request.
|
|
@@ -852,7 +855,16 @@ export class XMLHttpRequestController {
|
|
|
852
855
|
case 'append':
|
|
853
856
|
case 'set': {
|
|
854
857
|
const [headerName, headerValue] = args as [string, string]
|
|
855
|
-
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* @note Forward only the headers the Fetch API Request accepted.
|
|
861
|
+
* Forbidden request headers (e.g. "Cookie") are dropped silently
|
|
862
|
+
* by the request's headers guard, and forwarding them makes
|
|
863
|
+
* the browser refuse them with an error in the console.
|
|
864
|
+
*/
|
|
865
|
+
if (headers.has(headerName)) {
|
|
866
|
+
this.request.setRequestHeader(headerName, headerValue)
|
|
867
|
+
}
|
|
856
868
|
break
|
|
857
869
|
}
|
|
858
870
|
|
|
@@ -865,7 +877,7 @@ export class XMLHttpRequestController {
|
|
|
865
877
|
}
|
|
866
878
|
}
|
|
867
879
|
|
|
868
|
-
return
|
|
880
|
+
return result
|
|
869
881
|
},
|
|
870
882
|
})
|
|
871
883
|
define(fetchRequest, 'headers', proxyHeaders)
|