Commit a09b0ce5 authored by Guillaume Royer's avatar Guillaume Royer

fix(xhr2): handle FormData response type

parent a1342e11
// Generated by CoffeeScript 1.12.2 // Generated by CoffeeScript 1.12.7
(function() { (function() {
var InvalidStateError, NetworkError, ProgressEvent, SecurityError, SyntaxError, XMLHttpRequest, XMLHttpRequestEventTarget, XMLHttpRequestUpload, http, https, os, url, var InvalidStateError, NetworkError, ProgressEvent, SecurityError, SyntaxError, XMLHttpRequest, XMLHttpRequestEventTarget, XMLHttpRequestUpload, http, https, os, url,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
...@@ -323,7 +323,7 @@ ...@@ -323,7 +323,7 @@
'access-control-request-method': true, 'access-control-request-method': true,
connection: true, connection: true,
'content-length': true, 'content-length': true,
// cookie: true, cookie: true,
cookie2: true, cookie2: true,
date: true, date: true,
dnt: true, dnt: true,
...@@ -341,7 +341,7 @@ ...@@ -341,7 +341,7 @@
}; };
XMLHttpRequest.prototype._privateHeaders = { XMLHttpRequest.prototype._privateHeaders = {
// 'set-cookie': true, 'set-cookie': true,
'set-cookie2': true 'set-cookie2': true
}; };
...@@ -363,6 +363,7 @@ ...@@ -363,6 +363,7 @@
}; };
XMLHttpRequest.prototype._sendHttp = function(data) { XMLHttpRequest.prototype._sendHttp = function(data) {
var that;
if (this._sync) { if (this._sync) {
throw new Error("Synchronous XHR processing not implemented"); throw new Error("Synchronous XHR processing not implemented");
} }
...@@ -372,9 +373,11 @@ ...@@ -372,9 +373,11 @@
} else { } else {
data || (data = ''); data || (data = '');
} }
this.upload._setData(data); that = this;
this._finalizeHeaders(); this.upload._setData(data, function() {
this._sendHxxpRequest(); that._finalizeHeaders();
return that._sendHxxpRequest();
});
return void 0; return void 0;
}; };
...@@ -709,11 +712,13 @@ ...@@ -709,11 +712,13 @@
XMLHttpRequest.XMLHttpRequest = XMLHttpRequest; XMLHttpRequest.XMLHttpRequest = XMLHttpRequest;
XMLHttpRequest.FormData = FormData;
SecurityError = (function(superClass) { SecurityError = (function(superClass) {
extend(SecurityError, superClass); extend(SecurityError, superClass);
function SecurityError() { function SecurityError() {
SecurityError.__super__.constructor.apply(this, arguments); SecurityError.__super__.constructor.call(this);
} }
return SecurityError; return SecurityError;
...@@ -726,7 +731,7 @@ ...@@ -726,7 +731,7 @@
extend(InvalidStateError, superClass); extend(InvalidStateError, superClass);
function InvalidStateError() { function InvalidStateError() {
InvalidStateError.__super__.constructor.apply(this, arguments); InvalidStateError.__super__.constructor.call(this);
} }
return InvalidStateError; return InvalidStateError;
...@@ -750,7 +755,7 @@ ...@@ -750,7 +755,7 @@
extend(NetworkError, superClass); extend(NetworkError, superClass);
function NetworkError() { function NetworkError() {
NetworkError.__super__.constructor.apply(this, arguments); NetworkError.__super__.constructor.call(this);
} }
return NetworkError; return NetworkError;
...@@ -763,7 +768,7 @@ ...@@ -763,7 +768,7 @@
extend(SyntaxError, superClass); extend(SyntaxError, superClass);
function SyntaxError() { function SyntaxError() {
SyntaxError.__super__.constructor.apply(this, arguments); SyntaxError.__super__.constructor.call(this);
} }
return SyntaxError; return SyntaxError;
...@@ -813,10 +818,10 @@ ...@@ -813,10 +818,10 @@
return void 0; return void 0;
}; };
XMLHttpRequestUpload.prototype._setData = function(data) { XMLHttpRequestUpload.prototype._setData = function(data, cb) {
var body, i, j, k, offset, ref, ref1, view; var body, i, j, k, offset, ref, ref1, that, view;
if (typeof data === 'undefined' || data === null) { if (typeof data === 'undefined' || data === null) {
return; return cb();
} }
if (typeof data === 'string') { if (typeof data === 'string') {
if (data.length !== 0) { if (data.length !== 0) {
...@@ -840,10 +845,23 @@ ...@@ -840,10 +845,23 @@
body[i] = view[i + offset]; body[i] = view[i + offset];
} }
this._body = body; this._body = body;
} else if (data instanceof FormData) {
body = '';
this._contentType = data.getHeaders()['content-type'];
data.on('data', function(data) {
return body += data.toString();
});
that = this;
data.on('end', function() {
that._body = body;
return cb();
});
data.resume();
return;
} else { } else {
throw new Error("Unsupported send() data " + data); throw new Error("Unsupported send() data " + data);
} }
return void 0; return cb();
}; };
XMLHttpRequestUpload.prototype._finalizeHeaders = function(headers, loweredHeaders) { XMLHttpRequestUpload.prototype._finalizeHeaders = function(headers, loweredHeaders) {
...@@ -872,4 +890,4 @@ ...@@ -872,4 +890,4 @@
XMLHttpRequest.XMLHttpRequestUpload = XMLHttpRequestUpload; XMLHttpRequest.XMLHttpRequestUpload = XMLHttpRequestUpload;
}).call(this); }).call(this);
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment