Skip to content

Conversation

@emiedonmokumo
Copy link
Contributor

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-urlencoded instead of multipart/form-data; boundary=....

Problem

In Node.js, the fetch adapter did not correctly set the Content-Type header when sending FormData.
This caused requests using FormData to fail or be misinterpreted by servers expecting multipart/form-data with the proper boundary.
The issue was confirmed in axios#6993 and affects only the Node.js environment; browser behavior remains correct.

Solution

  • Detects if the request body is FormData and has a getHeaders() method (from the form-data package).
  • Uses data.getHeaders()['content-type'] to get the correct Content-Type header including the boundary.
  • Sets the header in the request before sending.
  • Added a proper Node.js test using the form-data package to verify the Content-Type header is correctly set with a boundary:
    const FormData = (await import('form-data')).default;
    const form = new FormData();
    form.append('foo', 'bar');
    
    server = await startHTTPServer((req, res) => {
      const contentType = req.headers['content-type'];
      expect(contentType).to.match(/^multipart\/form-data; boundary=/i);
      res.end('OK');
    });
    
    await fetchAxios.post('/form', form);

@github-actions github-actions bot added the pr::fix PR that fixes a bug label Aug 22, 2025

This comment was marked as outdated.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Member

@jasonsaayman jasonsaayman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good i just question if need to include chai? i think its unnecessary to include it as we use the built in assertions

@emiedonmokumo
Copy link
Contributor Author

Alright, thanks for the response, will definitely make the update

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-data Content-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.

Copy link
Member

@jasonsaayman jasonsaayman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the contribution 🔥

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@emiedonmokumo
Copy link
Contributor Author

Looking forward to making more contributions. Any tips on how I can easily understand the folder structure?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@jasonsaayman
Copy link
Member

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

@jasonsaayman jasonsaayman added this to the v1.12.0 milestone Aug 25, 2025
@jasonsaayman jasonsaayman merged commit a9f47af into axios:v1.x Aug 25, 2025
12 checks passed
@emiedonmokumo
Copy link
Contributor Author

Thank you very much.

@github-actions github-actions bot mentioned this pull request Sep 11, 2025
@github-actions
Copy link
Contributor

Hi, @emiedonmokumo! This PR has been published in v1.12.0 release. Thank you for your contribution ❤️!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr::fix PR that fixes a bug v1.12.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants