Skip to content

Commit

Permalink
fix(formdata): fixed automatic addition of the Content-Type header …
Browse files Browse the repository at this point in the history
…for FormData in non-browser environments; (axios#5917)
  • Loading branch information
DigitalBrainJS committed Sep 24, 2023
1 parent 4c89f25 commit bc9af51
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/adapters/xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,16 @@ export default isXHRAdapterSupported && function (config) {
}
}

let contentType;

if (utils.isFormData(requestData)) {
if (platform.isStandardBrowserEnv || platform.isStandardBrowserWebWorkerEnv) {
requestHeaders.setContentType(false); // Let the browser set it
} else {
requestHeaders.setContentType('multipart/form-data;', false); // mobile/desktop app frameworks
} else if(!requestHeaders.getContentType(/^\s*multipart\/form-data/)){
requestHeaders.setContentType('multipart/form-data'); // mobile/desktop app frameworks
} else if(utils.isString(contentType = requestHeaders.getContentType())){
// fix semicolon duplication issue for ReactNative FormData implementation
requestHeaders.setContentType(contentType.replace(/^\s*(multipart\/form-data);+/, '$1'))
}
}

Expand Down

0 comments on commit bc9af51

Please sign in to comment.