Fix: properly handling redirects with status code (#4561)

* Fix: properly handling redirects with status code

* fix: updated redirect logic for method change
This commit is contained in:
naman-bruno
2025-05-16 17:14:37 +05:30
committed by GitHub
parent 9f044c48fe
commit 2bb56e8a4b

View File

@@ -309,6 +309,27 @@ function makeAxiosInstance({
},
};
// Apply proper HTTP redirect behavior based on status code
const statusCode = error.response.status;
const originalMethod = (error.config.method || 'get').toLowerCase();
// For 301, 302, 303: change method to GET unless it was HEAD
if ([301, 302, 303].includes(statusCode) && originalMethod !== 'head') {
requestConfig.method = 'get';
requestConfig.data = undefined;
delete requestConfig.headers['content-length'];
delete requestConfig.headers['Content-Length'];
delete requestConfig.headers['content-type'];
delete requestConfig.headers['Content-Type'];
timeline.push({
timestamp: new Date(),
type: 'info',
message: `Changed method from ${originalMethod.toUpperCase()} to GET for ${statusCode} redirect and removed request body`,
});
}
if (preferencesUtil.shouldSendCookies()) {
const cookieString = getCookieStringForUrl(redirectUrl);
if (cookieString && typeof cookieString === 'string' && cookieString.length) {
@@ -316,7 +337,7 @@ function makeAxiosInstance({
}
}
try {
try {
setupProxyAgents({
requestConfig,
proxyMode,