mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
fix: exception to sending formdata in webworker (#5139)
Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
+1
-1
@@ -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
|
requestHeaders.setContentType(false); // Let the browser set it
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,24 @@ const isStandardBrowserEnv = (() => {
|
|||||||
return typeof window !== 'undefined' && typeof document !== 'undefined';
|
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 {
|
export default {
|
||||||
isBrowser: true,
|
isBrowser: true,
|
||||||
classes: {
|
classes: {
|
||||||
@@ -39,5 +57,6 @@ export default {
|
|||||||
Blob
|
Blob
|
||||||
},
|
},
|
||||||
isStandardBrowserEnv,
|
isStandardBrowserEnv,
|
||||||
|
isStandardBrowserWebWorkerEnv,
|
||||||
protocols: ['http', 'https', 'file', 'blob', 'url', 'data']
|
protocols: ['http', 'https', 'file', 'blob', 'url', 'data']
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user