From ce8775c75cdb4b6546503c2e6a311a14c2ad2b8c Mon Sep 17 00:00:00 2001 From: Pooja Date: Wed, 11 Mar 2026 19:01:14 +0530 Subject: [PATCH] fix: multipart header check (#7444) * fix: multipart header check * fix --- packages/bruno-cli/src/runner/run-single-request.js | 8 ++++---- packages/bruno-electron/src/ipc/network/index.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/bruno-cli/src/runner/run-single-request.js b/packages/bruno-cli/src/runner/run-single-request.js index 259a6f0fb..44ad9e54e 100644 --- a/packages/bruno-cli/src/runner/run-single-request.js +++ b/packages/bruno-cli/src/runner/run-single-request.js @@ -559,18 +559,18 @@ const runSingleRequest = async function ( // if `data` is of string type - return as-is (assumes already encoded) } - if (contentTypeHeader && contentTypeHeader.startsWith('multipart/')) { + const contentType = contentTypeHeader ? request.headers[contentTypeHeader] : ''; + if (typeof contentType === 'string' && contentType.startsWith('multipart/')) { if (!isFormData(request?.data)) { request._originalMultipartData = request.data; request.collectionPath = collectionPath; let form = createFormData(request.data, collectionPath); request.data = form; - if (request?.headers?.['content-type'] !== 'multipart/form-data') { + if (contentType !== 'multipart/form-data') { // Patch: Axios leverages getHeaders method to get the headers so FormData should be monkey patched const formHeaders = form.getHeaders(); - const ct = request.headers['content-type']; - formHeaders['content-type'] = `${ct}; boundary=${form.getBoundary()}`; + formHeaders['content-type'] = `${contentType}; boundary=${form.getBoundary()}`; form.getHeaders = function () { return formHeaders; }; diff --git a/packages/bruno-electron/src/ipc/network/index.js b/packages/bruno-electron/src/ipc/network/index.js index 5e8a935ba..dbbe2e12e 100644 --- a/packages/bruno-electron/src/ipc/network/index.js +++ b/packages/bruno-electron/src/ipc/network/index.js @@ -594,17 +594,17 @@ const registerNetworkIpc = (mainWindow) => { // if `data` is of string type - return as-is (assumes already encoded) } - if (contentTypeHeader && contentTypeHeader.startsWith('multipart/')) { + const contentType = contentTypeHeader ? request.headers[contentTypeHeader] : ''; + if (typeof contentType === 'string' && contentType.startsWith('multipart/')) { if (!isFormData(request.data)) { request._originalMultipartData = request.data; request.collectionPath = collectionPath; let form = createFormData(request.data, collectionPath); request.data = form; - if (contentTypeHeader !== 'multipart/form-data') { + if (contentType !== 'multipart/form-data') { // Patch: Axios leverages getHeaders method to get the headers so FormData should be monkey patched const formHeaders = form.getHeaders(); - const ct = contentTypeHeader; - formHeaders['content-type'] = `${ct}; boundary=${form.getBoundary()}`; + formHeaders['content-type'] = `${contentType}; boundary=${form.getBoundary()}`; form.getHeaders = function () { return formHeaders; };