Fixes #7494 Fetch Adapter: Content length header is missing in POST request#10633
Fixes #7494 Fetch Adapter: Content length header is missing in POST request#10633Kilros0817 wants to merge 5 commits intoaxios:v1.xfrom
Conversation
There was a problem hiding this comment.
1 issue found across 1 file
Confidence score: 3/5
- There is some risk of user-impacting regressions because
lib/adapters/fetch.jsnow prebuffers FormData to compute Content-Length, which can significantly increase memory use and latency on large uploads. - Severity is medium (6/10) with a clear performance impact path, so this is more than a minor housekeeping change.
- Pay close attention to
lib/adapters/fetch.js- prebuffering FormData may cause memory/latency regressions on large uploads.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="lib/adapters/fetch.js">
<violation number="1" location="lib/adapters/fetch.js:179">
P2: Node fetch path now prebuffers spec-compliant FormData to compute Content-Length, risking major memory/latency regressions on large uploads.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
f507291 to
b4065f3
Compare
|
@cubic-dev-ai Could you please read this comment? |
@Kilros0817 You're right, and I appreciate the clarification. Looking closely at the implementation in
The logic correctly omits For more details on how these rules are applied, you can check the Axios wiki. |
|
@Kilros0817 can we maybe add some testing here? |
There was a problem hiding this comment.
Content-Length and Accept-Encoding are set automatically by fetch. Besides, we can't be sure what compression algorithms are actually supported by fetch on each platform, so we shouldn't hardcode it.
Setting User-Agent is a valid change, as by default it sets it to 'node'.
|
Thanks @DigitalBrainJS I think we can close this @Kilros0817 please can you open a new PR with only the |
Description
Fixes inconsistency between the fetch adapter and the default http adapter in Node.js, where several headers are not automatically included.
Issues #7494
Problem
When using Axios fetch adapter in Node.js (v1.13.6), the following headers are not automatically set, unlike the default http adapter:
User-Agent
Content-Length
Accept-Encoding
Host
Connection
This leads to inconsistent behavior between adapters and may cause issues with servers that rely on these headers.
Solution
This PR updates the fetch adapter to align with the default http adapter behavior in Node.js:
Adds User-Agent: axios/ if not already provided
Adds Accept-Encoding: gzip, compress, deflate, br if not already provided
Computes and sets Content-Length when possible
Notes
Host and Connection headers are intentionally not set
These are controlled internally by the fetch implementation
Manually setting them is either ignored or disallowed (forbidden headers)
Testing
Verified headers are correctly added when using the fetch adapter in Node.js
Confirmed no override occurs if headers are explicitly provided by the user
Summary by cubic
Aligns the Node.js
fetchadapter with the Nodehttpadapter by auto-settingUser-Agent,Accept-Encoding, and computingContent-Lengthwhen safe. Fixes #7494 to prevent missing headers in POST requests; no browser changes.Description
lib/adapters/fetch.jsusingVERSION.User-Agent: axios/<version>andAccept-Encoding: gzip, compress, deflate, brif missing.Content-Lengthfor measurable bodies (Blob, ArrayBuffer/View, string, URLSearchParams); skipFormData/streams.HostorConnection(managed by fetch).httpadapter.v1.x; no behavior change.Docs
fetchadapter in Node.Testing
Content-Lengthset for measurable bodies; skipped forFormData/streams.Written for commit c61f3a5. Summary will update on new commits.