Developer set Content type header deleted if data is blob/file. (Caused by #1773)
See original GitHub issueDescribe the bug
I have a chunked file uploader, all data is to be sent as application/octet-stream in PUT in a binary stream. This worked in 0.19.2.
However, 0.20.0 fails because of code added under #1773 “Fixing overwrite Blob/File type as Content-Type in browser.”.
Line 21 lib/adapters/xhr.js:
if (
(utils.isBlob(requestData) || utils.isFile(requestData)) &&
requestData.type
) {
delete requestHeaders['Content-Type']; // Let the browser set it
}
This “fix” now breaks my application as it assumes the browser knows best - it doesn’t. It also is semantically inaccurate to set the content type to something like image/jpeg when the data is 20MB chunk from the middle of a jpeg file - the data is NOT of content type image/jpeg.
The “fix” applied in #1773 appears to be fixing overwrite caused by setting of default content-type headers but this solution removes ANY control over the header by the developer when dealing with Blobs.
To Reproduce
Simply set content-type in a request where the payload is a blob.
Expected behavior
Axios should NOT delete the content type header set by the developer specifically on the request. The power to control this should remain with the calling code and not be dictated by the library.
Environment
- Axios Version 0.20.0
- Adapter XHR
- Browser ALL
- Browser Version ALL
- Node.js Version n/a
- OS: ALL (Linux, Windows, mac)
Additional context/Screenshots
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:8 (3 by maintainers)
I have merged as this makes sense to me that Axios should not dictate headers it seems a bit counterproductive or if we do try to sense a header we should at least allow overrides to work.
@Gerhut Any idea when this change will be reverted/fixed? I’d hate to have to revert to
0.19.x
just for this one issue.