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 <lohxt.space@gmail.com>
Co-authored-by: Anoop M D <anoop.md1421@gmail.com>
This commit is contained in:
Grégoire Bellon 2024-09-05 08:56:12 +02:00 committed by GitHub
parent 2191550061
commit 450b1d3ae3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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
});