From ef23605d6912f4d4183ac066ef92a7bec2708dcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20BELLON?= Date: Wed, 12 Jun 2024 16:35:41 +0200 Subject: [PATCH 1/3] fix: invalid json body mistakenly quoted --- .../src/ipc/network/axios-instance.js | 17 ++++++++++++++++- 1 file changed, 16 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 dcc57a07e0..2744ed466f 100644 --- a/packages/bruno-electron/src/ipc/network/axios-instance.js +++ b/packages/bruno-electron/src/ipc/network/axios-instance.js @@ -49,7 +49,22 @@ const checkConnection = (host, port) => */ function makeAxiosInstance() { /** @type {axios.AxiosInstance} */ - const instance = axios.create(); + const instance = axios.create({ + transformRequest: function transformRequest(data, headers) { + // doesn't apply the default transformRequest if the data is a string, so that axios doesn't add quotes see : + // https://github.com/usebruno/bruno/issues/2043 + // https://github.com/axios/axios/issues/4034 + const hasJSONContentType = () => { + const contentType = (headers && headers['Content-Type']) || ''; + return contentType.indexOf('application/json') > -1; + }; + if (typeof data === 'string' && hasJSONContentType()) { + return data; + } + + axios.defaults.transformRequest.forEach((tr) => tr(data, headers)); + } + }); instance.interceptors.request.use(async (config) => { const url = URL.parse(config.url); From 7b34efadb4c29428bb2740b59e77efa98fff2802 Mon Sep 17 00:00:00 2001 From: lohit Date: Mon, 2 Sep 2024 17:17:32 +0530 Subject: [PATCH 2/3] Update axios-instance.js --- packages/bruno-electron/src/ipc/network/axios-instance.js | 4 +++- 1 file changed, 3 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 2744ed466f..ff25055d11 100644 --- a/packages/bruno-electron/src/ipc/network/axios-instance.js +++ b/packages/bruno-electron/src/ipc/network/axios-instance.js @@ -62,7 +62,9 @@ function makeAxiosInstance() { return data; } - axios.defaults.transformRequest.forEach((tr) => tr(data, headers)); + axios.defaults.transformRequest.forEach((tr) => data = tr(data, headers)); + return data; + } }); From 73265a75a11b60da816b0d71ca2d41b29d492144 Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Thu, 5 Sep 2024 12:24:21 +0530 Subject: [PATCH 3/3] chore: better code for json header check --- .../bruno-electron/src/ipc/network/axios-instance.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/bruno-electron/src/ipc/network/axios-instance.js b/packages/bruno-electron/src/ipc/network/axios-instance.js index ff25055d11..a93a8db654 100644 --- a/packages/bruno-electron/src/ipc/network/axios-instance.js +++ b/packages/bruno-electron/src/ipc/network/axios-instance.js @@ -54,17 +54,14 @@ function makeAxiosInstance() { // doesn't apply the default transformRequest if the data is a string, so that axios doesn't add quotes see : // https://github.com/usebruno/bruno/issues/2043 // https://github.com/axios/axios/issues/4034 - const hasJSONContentType = () => { - const contentType = (headers && headers['Content-Type']) || ''; - return contentType.indexOf('application/json') > -1; - }; - if (typeof data === 'string' && hasJSONContentType()) { + const contentType = headers?.['Content-Type'] || headers?.['content-type'] || ''; + const hasJSONContentType = contentType.includes('json'); + if (typeof data === 'string' && hasJSONContentType) { return data; } axios.defaults.transformRequest.forEach((tr) => data = tr(data, headers)); return data; - } });