mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
fix: missing beforeRedirect requestDetails argument (#6241)
This commit is contained in:
+2
-1
@@ -495,7 +495,8 @@ declare namespace axios {
|
|||||||
maxRate?: number | [MaxUploadRate, MaxDownloadRate];
|
maxRate?: number | [MaxUploadRate, MaxDownloadRate];
|
||||||
beforeRedirect?: (
|
beforeRedirect?: (
|
||||||
options: Record<string, any>,
|
options: Record<string, any>,
|
||||||
responseDetails: { headers: Record<string, string>; statusCode: HttpStatusCode }
|
responseDetails: { headers: Record<string, string>; statusCode: HttpStatusCode },
|
||||||
|
requestDetails: { headers: Record<string, string>; url: string; method: string },
|
||||||
) => void;
|
) => void;
|
||||||
socketPath?: string | null;
|
socketPath?: string | null;
|
||||||
allowedSocketPaths?: string | string[] | null;
|
allowedSocketPaths?: string | string[] | null;
|
||||||
|
|||||||
Vendored
+6
-1
@@ -394,7 +394,12 @@ export interface AxiosRequestConfig<D = any> {
|
|||||||
responseDetails: {
|
responseDetails: {
|
||||||
headers: Record<string, string>;
|
headers: Record<string, string>;
|
||||||
statusCode: HttpStatusCode;
|
statusCode: HttpStatusCode;
|
||||||
}
|
},
|
||||||
|
requestDetails: {
|
||||||
|
headers: Record<string, string>;
|
||||||
|
url: string;
|
||||||
|
method: string;
|
||||||
|
},
|
||||||
) => void;
|
) => void;
|
||||||
socketPath?: string | null;
|
socketPath?: string | null;
|
||||||
allowedSocketPaths?: string | string[] | null;
|
allowedSocketPaths?: string | string[] | null;
|
||||||
|
|||||||
@@ -176,12 +176,12 @@ const http2Sessions = new Http2Sessions();
|
|||||||
*
|
*
|
||||||
* @returns {Object<string, any>}
|
* @returns {Object<string, any>}
|
||||||
*/
|
*/
|
||||||
function dispatchBeforeRedirect(options, responseDetails) {
|
function dispatchBeforeRedirect(options, responseDetails, requestDetails) {
|
||||||
if (options.beforeRedirects.proxy) {
|
if (options.beforeRedirects.proxy) {
|
||||||
options.beforeRedirects.proxy(options);
|
options.beforeRedirects.proxy(options);
|
||||||
}
|
}
|
||||||
if (options.beforeRedirects.config) {
|
if (options.beforeRedirects.config) {
|
||||||
options.beforeRedirects.config(options, responseDetails);
|
options.beforeRedirects.config(options, responseDetails, requestDetails);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -385,6 +385,37 @@ describe('supports http with nodejs', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should pass requestDetails to beforeRedirect with the original URL', async () => {
|
||||||
|
const server = await startHTTPServer(
|
||||||
|
(req, res) => {
|
||||||
|
res.setHeader('Location', '/foo');
|
||||||
|
res.statusCode = 302;
|
||||||
|
res.end();
|
||||||
|
},
|
||||||
|
{ port: SERVER_PORT }
|
||||||
|
);
|
||||||
|
|
||||||
|
const originalUrl = `http://localhost:${server.address().port}/bar`;
|
||||||
|
let capturedUrl;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await axios.get(originalUrl, {
|
||||||
|
maxRedirects: 3,
|
||||||
|
beforeRedirect: (options, responseDetails, requestDetails) => {
|
||||||
|
if (options.path === '/foo' && responseDetails.headers.location === '/foo') {
|
||||||
|
capturedUrl = requestDetails.url;
|
||||||
|
throw new Error('Provided path is not allowed');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
assert.strictEqual(error.message, 'Redirected request failed: Provided path is not allowed');
|
||||||
|
assert.strictEqual(capturedUrl, originalUrl);
|
||||||
|
} finally {
|
||||||
|
await stopHTTPServer(server);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('should support beforeRedirect and proxy with redirect', async () => {
|
it('should support beforeRedirect and proxy with redirect', async () => {
|
||||||
let requestCount = 0;
|
let requestCount = 0;
|
||||||
let proxyUseCount = 0;
|
let proxyUseCount = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user