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 content type being added multiple times #74

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions Blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,24 @@
? TextDecoder.prototype.decode.bind(new TextDecoder())
: stringDecode

function handleXHRSend(_send, Blob, nativeBlob) {
var _setRequestHeader = XMLHttpRequest.prototype.setRequestHeader

XMLHttpRequest.prototype.setRequestHeader = function (name, value) {
if (name.toLowerCase() === 'content-type') this._hasContentType = true
_setRequestHeader.call(this, name, value)
}

XMLHttpRequest.prototype.send = function (data) {
if (data instanceof Blob) {
if (!this._hasContentType) this.setRequestHeader('Content-Type', data.type)
_send.call(this, nativeBlob ? data : textDecode(data._buffer))
} else {
_send.call(this, data)
}
}
}

function FakeBlobBuilder () {
function isDataView (obj) {
return obj && DataView.prototype.isPrototypeOf(obj)
Expand Down Expand Up @@ -490,14 +508,7 @@
/********************************************************/
var _send = global.XMLHttpRequest && global.XMLHttpRequest.prototype.send
if (_send) {
XMLHttpRequest.prototype.send = function (data) {
if (data instanceof Blob) {
this.setRequestHeader('Content-Type', data.type)
_send.call(this, textDecode(data._buffer))
} else {
_send.call(this, data)
}
}
handleXHRSend(_send, Blob, false)
}

global.FileReader = FileReader
Expand All @@ -516,14 +527,7 @@
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/6047383
var _send = global.XMLHttpRequest && global.XMLHttpRequest.prototype.send
if (isIE && _send) {
XMLHttpRequest.prototype.send = function (data) {
if (data instanceof Blob) {
this.setRequestHeader('Content-Type', data.type)
_send.call(this, data)
} else {
_send.call(this, data)
}
}
handleXHRSend(_send, Blob, true)
}

try {
Expand Down