fix(fetch-adapter): set correct Content-Type for Node FormData#6998
fix(fetch-adapter): set correct Content-Type for Node FormData#6998jasonsaayman merged 6 commits intoaxios:v1.xfrom
Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
jasonsaayman
left a comment
There was a problem hiding this comment.
looks good i just question if need to include chai? i think its unnecessary to include it as we use the built in assertions
|
Alright, thanks for the response, will definitely make the update |
There was a problem hiding this comment.
Pull Request Overview
Fixes Content-Type header handling for FormData in Node.js fetch adapter to properly set multipart/form-data with boundary instead of the incorrect application/x-www-form-urlencoded.
- Replaces complex header parsing logic with direct usage of FormData's
getHeaders()method - Adds Node.js-specific test to verify correct
multipart/form-dataContent-Type with boundary - Simplifies browser vs Node.js environment handling
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/helpers/resolveConfig.js | Updates FormData Content-Type handling to use getHeaders() for Node.js FormData |
| test/unit/adapters/fetch.js | Adds test case to verify correct Content-Type header for Node.js FormData |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
jasonsaayman
left a comment
There was a problem hiding this comment.
LGTM, thanks for the contribution 🔥
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Looking forward to making more contributions. Any tips on how I can easily understand the folder structure? |
honestly i only got used to this after a real long time, this is something i hope to vastly improve in the next version as the on-ramp is quite steep and it should not be. but i would say taking up more issue and trying to solve them can help with this |
|
Thank you very much. |
|
Hi, @emiedonmokumo! This PR has been published in v1.12.0 release. Thank you for your contribution ❤️! |
Summary
This pull request fixes an issue in the fetch adapter for Node.js where FormData requests were being sent with
application/x-www-form-urlencodedinstead ofmultipart/form-data; boundary=....Problem
In Node.js, the fetch adapter did not correctly set the
Content-Typeheader when sending FormData.This caused requests using FormData to fail or be misinterpreted by servers expecting
multipart/form-datawith the proper boundary.The issue was confirmed in axios#6993 and affects only the Node.js environment; browser behavior remains correct.
Solution
getHeaders()method (from theform-datapackage).data.getHeaders()['content-type']to get the correctContent-Typeheader including the boundary.form-datapackage to verify theContent-Typeheader is correctly set with a boundary: