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

fix: exception to sending formdata in webworker #5139

Merged
merged 2 commits into from Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/adapters/xhr.js
Expand Up @@ -61,7 +61,7 @@ export default isXHRAdapterSupported && function (config) {
}
}

if (utils.isFormData(requestData) && platform.isStandardBrowserEnv) {
if (utils.isFormData(requestData) && (platform.isStandardBrowserEnv || platform.isStandardBrowserWebWorkerEnv)) {
requestHeaders.setContentType(false); // Let the browser set it
}

Expand Down
19 changes: 19 additions & 0 deletions lib/platform/browser/index.js
Expand Up @@ -31,6 +31,24 @@ const isStandardBrowserEnv = (() => {
return typeof window !== 'undefined' && typeof document !== 'undefined';
})();

/**
* Determine if we're running in a standard browser webWorker environment
*
* Although the `isStandardBrowserEnv` method indicates that
* `allows axios to run in a web worker`, the WebWorker will still be
* filtered out due to its judgment standard
* `typeof window !== 'undefined' && typeof document !== 'undefined'`.
* This leads to a problem when axios post `FormData` in webWorker
*/
const isStandardBrowserWebWorkerEnv = (() => {
return (
typeof WorkerGlobalScope !== 'undefined' &&
self instanceof WorkerGlobalScope &&
typeof self.importScripts === 'function'
);
})();


export default {
isBrowser: true,
classes: {
Expand All @@ -39,5 +57,6 @@ export default {
Blob
},
isStandardBrowserEnv,
isStandardBrowserWebWorkerEnv,
protocols: ['http', 'https', 'file', 'blob', 'url', 'data']
};