Skip to content

Commit

Permalink
fix(formdata): fixed content-type header normalization for non-standa…
Browse files Browse the repository at this point in the history
…rd browser environments; (#6056)
  • Loading branch information
DigitalBrainJS committed Nov 7, 2023
1 parent 3dc8369 commit dd465ab
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/adapters/xhr.js
Expand Up @@ -66,11 +66,10 @@ export default isXHRAdapterSupported && function (config) {
if (utils.isFormData(requestData)) {
if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
requestHeaders.setContentType(false); // Let the browser set it
} else if(!requestHeaders.getContentType(/^\s*multipart\/form-data/)){
requestHeaders.setContentType('multipart/form-data'); // mobile/desktop app frameworks
} else if(utils.isString(contentType = requestHeaders.getContentType())){
} else if ((contentType = requestHeaders.getContentType()) !== false) {
// fix semicolon duplication issue for ReactNative FormData implementation
requestHeaders.setContentType(contentType.replace(/^\s*(multipart\/form-data);+/, '$1'))
const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
requestHeaders.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
}
}

Expand Down

0 comments on commit dd465ab

Please sign in to comment.