From 606a2515008c868689961d3f2b4b2066d0fb3ab4 Mon Sep 17 00:00:00 2001 From: Andrey Kozitsyn Date: Fri, 26 Jan 2024 19:16:14 +0500 Subject: [PATCH] Adding support XMLHttpRequest.withCredentials parameter --- src/Options.ts | 1 + src/browser.ts | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/Options.ts b/src/Options.ts index 44293ad..352f7d7 100644 --- a/src/Options.ts +++ b/src/Options.ts @@ -17,6 +17,7 @@ interface Options { retryDelay?: number | ((err: NodeJS.ErrnoException | null, res: Response | void, attemptNumber: number) => number); socketTimeout?: number; timeout?: number; + withCredentials?: boolean; isMatch?: (requestHeaders: IncomingHttpHeaders, cachedResponse: CachedResponse, defaultValue: boolean) => boolean; isExpired?: (cachedResponse: CachedResponse, defaultValue: boolean) => boolean; diff --git a/src/browser.ts b/src/browser.ts index b0fbb04..5e7def3 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -108,6 +108,11 @@ function request(method: HttpVerb, url: string, options: Options): ResponsePromi reject(err); }; } + + if (options.withCredentials) { + xhr.withCredentials = options.withCredentials; + } + xhr.onreadystatechange = function () { if (xhr.readyState === 4) { var headers: {[key: string]: string} = {};