From a1938ff073fcb0f89011f001dfbc1fa1dc995e39 Mon Sep 17 00:00:00 2001 From: Zao Soula Date: Wed, 24 Jan 2024 22:57:06 +0000 Subject: [PATCH] fix: fixed missed dispatchBeforeRedirect argument (#5778) Co-authored-by: Dmitriy Mozgovoy --- index.d.cts | 2 +- index.d.ts | 2 +- lib/adapters/http.js | 4 ++-- test/unit/adapters/http.js | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/index.d.cts b/index.d.cts index 35a1f0f..d95e6ef 100644 --- a/index.d.cts +++ b/index.d.cts @@ -396,7 +396,7 @@ declare namespace axios { maxBodyLength?: number; maxRedirects?: number; maxRate?: number | [MaxUploadRate, MaxDownloadRate]; - beforeRedirect?: (options: Record, responseDetails: {headers: Record}) => void; + beforeRedirect?: (options: Record, responseDetails: {headers: Record, statusCode: HttpStatusCode}) => void; socketPath?: string | null; transport?: any; httpAgent?: any; diff --git a/index.d.ts b/index.d.ts index 3a2840b..02a8c09 100644 --- a/index.d.ts +++ b/index.d.ts @@ -337,7 +337,7 @@ export interface AxiosRequestConfig { maxBodyLength?: number; maxRedirects?: number; maxRate?: number | [MaxUploadRate, MaxDownloadRate]; - beforeRedirect?: (options: Record, responseDetails: { headers: Record }) => void; + beforeRedirect?: (options: Record, responseDetails: {headers: Record, statusCode: HttpStatusCode}) => void; socketPath?: string | null; transport?: any; httpAgent?: any; diff --git a/lib/adapters/http.js b/lib/adapters/http.js index 78255d2..21d6458 100755 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -53,12 +53,12 @@ const supportedProtocols = platform.protocols.map(protocol => { * * @returns {Object} */ -function dispatchBeforeRedirect(options) { +function dispatchBeforeRedirect(options, responseDetails) { if (options.beforeRedirects.proxy) { options.beforeRedirects.proxy(options); } if (options.beforeRedirects.config) { - options.beforeRedirects.config(options); + options.beforeRedirects.config(options, responseDetails); } } diff --git a/test/unit/adapters/http.js b/test/unit/adapters/http.js index bbfd093..0af2278 100644 --- a/test/unit/adapters/http.js +++ b/test/unit/adapters/http.js @@ -381,8 +381,8 @@ describe('supports http with nodejs', function () { }).listen(4444, function () { axios.get('http://localhost:4444/', { maxRedirects: 3, - beforeRedirect: function (options) { - if (options.path === '/foo') { + beforeRedirect: function (options, responseDetails) { + if (options.path === '/foo' && responseDetails.headers.location === '/foo') { throw new Error( 'Provided path is not allowed' );