From 4917f24b7cb02bbfae175fdc5079ed77a44fae2c Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Mon, 29 Jan 2024 19:46:41 +0530 Subject: [PATCH] fix(#1436): fixed inconsistent beheviour of res.getHeaders() api --- .../src/components/ResponsePane/ResponseHeaders/index.js | 6 ++++-- .../bruno-app/src/components/ResponsePane/Timeline/index.js | 2 +- packages/bruno-app/src/utils/network/index.js | 2 +- packages/bruno-electron/src/ipc/network/index.js | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/bruno-app/src/components/ResponsePane/ResponseHeaders/index.js b/packages/bruno-app/src/components/ResponsePane/ResponseHeaders/index.js index f18a5f947..9964a5f4b 100644 --- a/packages/bruno-app/src/components/ResponsePane/ResponseHeaders/index.js +++ b/packages/bruno-app/src/components/ResponsePane/ResponseHeaders/index.js @@ -2,6 +2,8 @@ import React from 'react'; import StyledWrapper from './StyledWrapper'; const ResponseHeaders = ({ headers }) => { + const headersArray = typeof headers === 'object' ? Object.entries(headers) : []; + return ( @@ -12,8 +14,8 @@ const ResponseHeaders = ({ headers }) => { - {headers && headers.length - ? headers.map((header, index) => { + {headersArray && headersArray.length + ? headersArray.map((header, index) => { return ( diff --git a/packages/bruno-app/src/components/ResponsePane/Timeline/index.js b/packages/bruno-app/src/components/ResponsePane/Timeline/index.js index 135627b16..d8a4770a5 100644 --- a/packages/bruno-app/src/components/ResponsePane/Timeline/index.js +++ b/packages/bruno-app/src/components/ResponsePane/Timeline/index.js @@ -5,7 +5,7 @@ import StyledWrapper from './StyledWrapper'; const Timeline = ({ request, response }) => { const requestHeaders = []; - const responseHeaders = response.headers || []; + const responseHeaders = typeof response.headers === 'object' ? Object.entries(response.headers) : []; request = request || {}; response = response || {}; diff --git a/packages/bruno-app/src/utils/network/index.js b/packages/bruno-app/src/utils/network/index.js index ffd66743f..4ee055fda 100644 --- a/packages/bruno-app/src/utils/network/index.js +++ b/packages/bruno-app/src/utils/network/index.js @@ -10,7 +10,7 @@ export const sendNetworkRequest = async (item, collection, environment, collecti data: response.data, // Note that the Buffer is encoded as a base64 string, because Buffers / TypedArrays are not allowed in the redux store dataBuffer: response.dataBuffer, - headers: Object.entries(response.headers), + headers: response.headers, size: response.size, status: response.status, statusText: response.statusText, diff --git a/packages/bruno-electron/src/ipc/network/index.js b/packages/bruno-electron/src/ipc/network/index.js index eb61d62d6..58e7dc638 100644 --- a/packages/bruno-electron/src/ipc/network/index.js +++ b/packages/bruno-electron/src/ipc/network/index.js @@ -792,7 +792,7 @@ const registerNetworkIpc = (mainWindow) => { responseReceived: { status: response.status, statusText: response.statusText, - headers: Object.entries(response.headers), + headers: response.headers, duration: timeEnd - timeStart, dataBuffer: dataBuffer.toString('base64'), size: Buffer.byteLength(dataBuffer), @@ -809,7 +809,7 @@ const registerNetworkIpc = (mainWindow) => { response = { status: error.response.status, statusText: error.response.statusText, - headers: Object.entries(error.response.headers), + headers: error.response.headers, duration: timeEnd - timeStart, dataBuffer: dataBuffer.toString('base64'), size: Buffer.byteLength(dataBuffer),
{header[0]}