From 450b1d3ae3983b44f260f2ca3e953174af945a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Bellon?= Date: Thu, 5 Sep 2024 08:56:12 +0200 Subject: [PATCH] fix: invalid json body mistakenly quoted (#2449) * fix: invalid json body mistakenly quoted * Update axios-instance.js * chore: better code for json header check --------- Co-authored-by: lohit Co-authored-by: Anoop M D --- .../src/ipc/network/axios-instance.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/bruno-electron/src/ipc/network/axios-instance.js b/packages/bruno-electron/src/ipc/network/axios-instance.js index da1584d42..a292973fe 100644 --- a/packages/bruno-electron/src/ipc/network/axios-instance.js +++ b/packages/bruno-electron/src/ipc/network/axios-instance.js @@ -50,6 +50,19 @@ const checkConnection = (host, port) => function makeAxiosInstance() { /** @type {axios.AxiosInstance} */ 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 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; + }, proxy: false });