From 2bb56e8a4b0a2d69f19675709bb5e2334e23254a Mon Sep 17 00:00:00 2001 From: naman-bruno Date: Fri, 16 May 2025 17:14:37 +0530 Subject: [PATCH] Fix: properly handling redirects with status code (#4561) * Fix: properly handling redirects with status code * fix: updated redirect logic for method change --- .../src/ipc/network/axios-instance.js | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/bruno-electron/src/ipc/network/axios-instance.js b/packages/bruno-electron/src/ipc/network/axios-instance.js index 5406f9869..e86d06fea 100644 --- a/packages/bruno-electron/src/ipc/network/axios-instance.js +++ b/packages/bruno-electron/src/ipc/network/axios-instance.js @@ -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,