From bba95761e2f2b54af1fcab8a7b1d626ca10d537e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Thu, 21 Dec 2023 13:32:04 +0100 Subject: [PATCH] fix(core): Prevent axios from force setting a form-urlencoded content-type (#8117) [Since v1 axios is force-setting a content-type of `application/x-www-form-urlencoded` on POST/PUT/PATCH requests, even if they have no payload](https://github.com/axios/axios/blob/v1.x/lib/core/dispatchRequest.js#L45-L47). This is causing nodes that do not support form-urlencoded bodies to fail. By setting the content-type to `false` (if a content-type wasn't already set), we force axios to not overwrite this header. [Workflows tests](https://github.com/n8n-io/n8n/actions/runs/7288103743/job/19860060607) --- packages/core/src/NodeExecuteFunctions.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/core/src/NodeExecuteFunctions.ts b/packages/core/src/NodeExecuteFunctions.ts index 659dbcae8e934..55cfdd2a1a269 100644 --- a/packages/core/src/NodeExecuteFunctions.ts +++ b/packages/core/src/NodeExecuteFunctions.ts @@ -162,6 +162,13 @@ axios.defaults.paramsSerializer = (params) => { } return stringify(params, { arrayFormat: 'indices' }); }; +axios.interceptors.request.use((config) => { + // If no content-type is set by us, prevent axios from force-setting the content-type to `application/x-www-form-urlencoded` + if (config.data === undefined) { + config.headers.setContentType(false, false); + } + return config; +}); const pushFormDataValue = (form: FormData, key: string, value: any) => { if (value?.hasOwnProperty('value') && value.hasOwnProperty('options')) {