Skip to content

Commit

Permalink
fix(core): Prevent axios from force setting a form-urlencoded content…
Browse files Browse the repository at this point in the history
…-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)
  • Loading branch information
netroy authored Dec 21, 2023
1 parent 32d397e commit bba9576
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/core/src/NodeExecuteFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down

0 comments on commit bba9576

Please sign in to comment.