Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed FormData posting in browser environment by reverting #3785; #4640

Merged
merged 4 commits into from Apr 27, 2022

Conversation

DigitalBrainJS
Copy link
Contributor

@DigitalBrainJS DigitalBrainJS commented Apr 26, 2022

Not sure why, but PR #3785 removed the code that deletes the content-type header in case of FormData payload for xhr adapter (browser build); This breaks the FormData support for the browser.
Update: now it removes the content-type header only for the standard browser environment. React native should keep the original header from the config.
Closes #4631

@DigitalBrainJS DigitalBrainJS marked this pull request as draft Apr 26, 2022
@DigitalBrainJS DigitalBrainJS marked this pull request as ready for review Apr 26, 2022
@DigitalBrainJS DigitalBrainJS changed the title Fixed posting FormData in browser environment by reverting #3785; Fixed FormData posting in browser environment by reverting #3785; Apr 26, 2022
@@ -27,6 +27,10 @@ module.exports = function xhrAdapter(config) {
}
}

if (utils.isFormData(requestData) && utils.isStandardBrowserEnv()) {
delete requestHeaders['Content-Type']; // Let the browser set it

Choose a reason for hiding this comment

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

Shouldn't this be done further down in order to use normalised headers?

Using this here would only catch the specific casing Content-Type and not content-type

Copy link
Contributor Author

@DigitalBrainJS DigitalBrainJS Apr 26, 2022

Choose a reason for hiding this comment

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

Probably yes, but this PR only brings back the removed code and adds an additional environment check to fix the regression bug. Axios headers helper is far away from perfection, and it should be deeply refactored to be really caseless, not just locally.
Unfortunately, the PR #4215 where the headers helper is reworked is still not merged, so it would be better to keep it as it was for a while.
https://github.com/axios/axios/pull/4215/files#diff-e3e3dd5daf3f63345305a7397f39f6adce58f3ff9b987a96da808b060079958b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants