Repository navigation
Conversation
The fetch adapter only dropped a multipart/form-data Content-Type without a boundary, so in Node.js a native FormData body kept the application/x-www-form-urlencoded default while fetch sent a multipart body. Drop any Content-Type except multipart/form-data with a boundary so fetch sets the header with its own boundary.
[Medium impact] The PR appears safe to merge; no actionable defects were found. SummaryFixes native
No actionable issues found. Review was based on source inspection; no tests were run during this review. Reviews (8) · Last reviewed commit: "Merge remote-tracking branch 'upstream/v..." · Reviewed by Greptile |
jasonsaayman
left a comment
There was a problem hiding this comment.
PR #11351 - fix(fetch): send native FormData as multipart/form-data in Node.js
Repo: axios/axios Author: @spokodev Base: v1.x Files: 3 **+48/-3
CI: 4 success; no build/test workflow result is present in this snapshot. Mergeability: mergeable. Reviewed head: 88bd9aedaa28f0dd468a39420dd818081027816e.
Repo Profile
Axios is an npm JavaScript HTTP client for browsers and Node, with XHR/Fetch/HTTP adapters, default and named exports, interceptors, headers/errors, and paired ESM/CJS declarations. The target uses Vitest plus browser and package/module tests; v1 packaging covers older Node CJS runtimes as well as current ESM, Bun and Deno. Contributions preserve transport/security boundaries, add regression coverage and prerelease records, and defer unreleased user docs to PRE_RELEASE_DOCS.md. This review uses the actual target-branch guidance and files, not the separate local v0 checkout.
Verdict
Request changes — No concrete source defect found in this review; the missing latest-head validation prevent merge approval.
Posted as a comment review for the validation/integration hold; no formal code-change request is implied beyond the specific items below.
Change Explanation And User Impact
Native FormData reaches the Fetch adapter after dispatchRequest has installed the ordinary POST/PUT/PATCH content-type default. Fetch generates multipart bytes, but the existing non-multipart header prevents the runtime from supplying their matching boundary. This change removes that conflicting header for the native FormData path while preserving explicit multipart boundaries handled by the serializer. Executed against a local HTTP receiver: axios.post(url, form, {adapter: "fetch"}) with foo=bar previously arrived as application/x-www-form-urlencoded and parsed as a malformed field; this head arrived as multipart/form-data with a boundary and parsed as foo=bar. Requests using upload tracking, a body limit, or an explicit boundary also need the existing serialized-Blob path to remain consistent.
Validation scope: source/diff and regression-test review. Examples explicitly marked executed used isolated source snapshots on Node 24.18.0 with the workspace dependency installation; these were focused checks, not a clean install, full CI matrix, or full test-suite run. Author-reported test results were not treated as independently executed.
Competing PRs
Search: axios/axios open PRs, including drafts; full open-list scan plus FormData multipart in:title,body, filename in:title,body. Complementary searches were run across related APIs/issues; no query reached the 100-result cap and no search failed. The five explicitly excluded PRs were not reviewed or modified in this batch.
#11351 fixes native Fetch multipart headers; #11332 preserves empty filenames in the Node HTTP serializer. They operate at different boundaries and are complementary.
Preferred PR: No competing implementation supersedes this PR; continue it independently.
Unique contributions: The submitted regression cases protect this specific boundary; preserve them independently of adjacent fixes.
Action: No duplicate closure: the candidates are complementary or no equivalent solution was found.
Project Fit
North star: Reliable HTTP transport and configuration across supported JavaScript environments, without embedding application-specific policy.
Benefits: Makes Fetch multipart headers match the actual body boundary.
Tradeoffs: A caller-supplied non-multipart header is now replaced for a FormData body; that makes the wire representation coherent, but should be explicit in the release note.
Fit: Strong — The underlying problem belongs in the transport, serializer, declarations or their maintenance tests.
Adversarial Review
Strongest objection: A caller-supplied non-multipart header is now replaced for a FormData body; that makes the wire representation coherent, but should be explicit in the release note. Latest-head integration evidence is still needed.
Abuse/failure modes checked: Traced native versus serialized multipart paths, explicit boundaries, progress/body-limit selection, and the new post/put/patch header assertions. The local receiver also parsed the body successfully.
Result: No concrete source defect established in the examined cases; validation and integration limits remain below.
Disposition
Continue
Address the specific blockers below; no unrelated scope or complementary PR should be closed.
Semver
patch — Corrects existing behavior or strengthens internal tooling/tests without adding a public API.
Breaking Changes
None intended beyond the bug correction described above; no public API removal or new runtime requirement is introduced by this diff.
Documentation
PRE_RELEASE_CHANGELOG.md records the change. No new API reference or migration is required for this scoped correction; keep the release description consistent with the behavior and limits above.
Performance And Regression Risk
Hot path touched: Yes — request/response processing or its shared helpers.
Performance concern: No unbounded new work identified in the changed path. A caller-supplied non-multipart header is now replaced for a FormData body; that makes the wire representation coherent, but should be explicit in the release note.
Regression risk: low — the changed boundary needs regression and integration coverage, particularly after any rebase.
Evidence requested: The latest-head checks listed below; no extra benchmark requested for this scoped change.
Blocking Issues
- Latest-head build/test validation is unavailable in the returned GitHub checks. Run or attach the repository build, relevant regression suite and required package/type/browser checks before merge; review/security bots alone do not establish that they pass. This is a validation hold, not an invented source defect.
Non-Blocking Suggestions
- Add the receiver-side formData() assertion to the committed regression, so header and body boundary agreement are verified together.
Looks Good
- Traced native versus serialized multipart paths, explicit boundaries, progress/body-limit selection, and the new post/put/patch header assertions. The local receiver also parsed the body successfully.
Assert that the server can read the field back with the Content-Type it received, so a header whose boundary does not match the body also fails.
|
The build and test workflows have not run on this branch yet: Continuous integration, Verify build reproducibility, Bundle Size and zizmor are waiting for approval ( I added the receiver-side check in 58f6657. The test server now parses the body with The PRE_RELEASE_CHANGELOG entry already covers a caller-set non-multipart Content-Type being replaced. |
…rmdata-content-type # Conflicts: # PRE_RELEASE_CHANGELOG.md
…rmdata-content-type # Conflicts: # PRE_RELEASE_CHANGELOG.md
…rmdata-content-type # Conflicts: # PRE_RELEASE_CHANGELOG.md
|
I merged The CI workflows have not run on this branch yet and are waiting for "Approve and run workflows". Locally on Node 26, on this head, |
Summary
In Node.js,
axios.post(url, formData, { adapter: 'fetch' })with a nativeFormDatasendsContent-Type: application/x-www-form-urlencodedwhile fetch writes a multipart body, so the server cannot parse the form. The http adapter sendsmultipart/form-data; boundary=...for the same call.dispatchRequestsetsapplication/x-www-form-urlencodedas the default Content-Type for POST, PUT and PATCH.resolveConfigclears it forFormDataonly in browser-like environments, and the fetch adapter only removed amultipart/form-datatype without a boundary, so in Node.js the default reached the request. This change makes the fetch adapter remove any Content-Type on aFormDatabody exceptmultipart/form-datawith a boundary, so fetch sets the header with the boundary it generates.Linked issue
Related to #6993, which reported this symptom and was closed after #6998. #6998 handled
form-datapackage objects (getHeaders()); nativeFormDatain Node.js still sends the urlencoded type on 1.12.0, 1.20.0 and v1.x.Changes
lib/adapters/fetch.js: forFormDatabodies, keep only amultipart/form-dataContent-Type that has a boundary.tests/unit/adapters/fetch.test.js: nativeFormDatawith no Content-Type (post, put, patch) and with an explicit urlencoded Content-Type both arrive asmultipart/form-data; boundary=....PRE_RELEASE_CHANGELOG.md: Bug Fixes entry.Validation
Node.js v26.0.0, macOS arm64.
npm ci --ignore-scriptsnpm run lint: passed.npm run build: passed.npm run test:vitest:unit: 74 files, 1702 tests passed. Without thefetch.jschange the two new tests fail and the other 83 tests infetch.test.jspass.npm run test:vitest:browser:headless: 81 files, 1065 passed, 3 skipped (Playwright 1.64.0, Chromium, Firefox, WebKit).Response.formData(): on 1.20.0 the fetch adapter sendsapplication/x-www-form-urlencodedand the body does not parse; with this change it sendsmultipart/form-data; boundary=...and the server readsnameandfile, the same as the http adapter.Compatibility and documentation
Patch. Affects the fetch adapter outside browsers when the body is a native
FormData. A non-multipart Content-Type set explicitly for aFormDatabody is now replaced, as the http adapter and axios in browsers already do; before this change such a request could not be parsed. Amultipart/form-datatype with a boundary, such as one fromform-data'sgetHeaders(), is kept. Noindex.d.ts/index.d.ctsorPRE_RELEASE_DOCS.mdchanges are needed.Not covered here: a
form-datapackage instance orpostForm()with a plain object through the fetch adapter in Node.js still sends[object FormData]as the body. That is a separate problem.Checklist
PRE_RELEASE_CHANGELOG.mdentry added or updated (or AGENTS.md's automated release-preparation exception explained)AI assistance: Claude Code assisted with the investigation, the change, the tests and this description; I reviewed and ran everything above. I can't apply labels, so a maintainer needs to apply
ai-assisted.Summary by cubic
Description
Fixes the fetch adapter sending native
FormDatabodies withContent-Type: application/x-www-form-urlencodedin Node.js, which caused servers to receive an unparseable body since fetch actually serializes multipart data. The fetch adapter now removes anyContent-Typeon aFormDatabody that is notmultipart/form-datawith a boundary, letting fetch set the header and boundary it generates. This matches the behavior of the Node HTTP adapter and browser environments.multipart/form-datatype without a boundary, so theapplication/x-www-form-urlencodeddefault set bydispatchRequestreached the request in Node.js.multipart/form-datatype with a boundary, such as one from theform-datapackage'sgetHeaders(), is preserved.form-datapackage objects, not nativeFormData. APRE_RELEASE_CHANGELOG.mdBug Fixes entry links this pull request.Docs
No documentation update needed; no public API or type changes.
Testing
Added two tests: native
FormDatawith noContent-Type(POST, PUT, PATCH) and with an explicit urlencodedContent-Typeboth arrive asmultipart/form-data; boundary=.... Each test parses the body back on the receiving server, so a header whose boundary does not match the body also fails. Unit and headless browser suites pass.Semantic version impact
Patch. Only the fetch adapter behavior outside browsers changes for
FormDatabodies; no breaking changes, and an explicitly set non-multipartContent-Typeon aFormDatabody is now replaced, as the http adapter and browsers already do.Written for commit 0d7af1f. Summary will update on new commits.