2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-15 11:59:42 +03:00

fix: exception to sending formdata in webworker (#5139)

Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
wenzheng
2022-12-02 01:15:23 +08:00
committed by GitHub
parent 9041c7d272
commit e3d759491c
2 changed files with 20 additions and 1 deletions
+1 -1
View File
@@ -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
}
+19
View File
@@ -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: {
@@ -39,5 +57,6 @@ export default {
Blob
},
isStandardBrowserEnv,
isStandardBrowserWebWorkerEnv,
protocols: ['http', 'https', 'file', 'blob', 'url', 'data']
};