paypro: clean up makeshift $http module.

This commit is contained in:
Christopher Jeffrey 2014-08-04 10:28:55 -07:00 committed by Manuel Araoz
parent 8786fd9905
commit 04432aa426
1 changed files with 33 additions and 48 deletions

View File

@ -1565,7 +1565,8 @@ Wallet.prototype.verifySignedJson = function(senderId, payload, signature) {
// NOTE: Angular $http module does not send ArrayBuffers correctly, so we're
// not going to use it. We'll have to write our own. Otherwise, we could
// hex-encoded our messages and decode them on the other side, but that
// deviates from BIP-70 slightly.
// deviates from BIP-70.
// if (typeof angular !== 'undefined') {
// G.$http = G.$http || angular.bootstrap().get('$http');
// }
@ -1600,35 +1601,22 @@ G.$http = G.$http || function $http(options, callback) {
var req = options;
req.headers = req.headers || {};
req.body = req.body || {};
req.body = req.body || req.data || {};
if (typeof XMLHttpRequest !== 'undefined') {
var xhr = new XMLHttpRequest();
xhr.open(method, uri, true);
Object.keys(options.headers).forEach(function(key) {
var val = options.headers[key];
Object.keys(req.headers).forEach(function(key) {
var val = req.headers[key];
if (key === 'Content-Length') return;
if (key === 'Content-Transfer-Encoding') return;
xhr.setRequestHeader(key, val);
});
// For older browsers (binary data):
// xhr.overrideMimeType('text/plain; charset=x-user-defined');
// Newer browsers (binary data):
// xhr.responseType = 'arraybuffer';
if (options.responseType) {
xhr.responseType = options.responseType;
if (req.responseType) {
xhr.responseType = req.responseType;
}
// xhr.onreadystatechange = function() {
// if (xhr.readyState == 4) {
// ;
// }
// };
xhr.onload = function(event) {
var response = xhr.response;
var buf = new Uint8Array(response);
@ -1646,15 +1634,12 @@ G.$http = G.$http || function $http(options, callback) {
return ret._error(null, new Error(event.message), null, options);
};
if (options.data || options.body) {
xhr.send(options.data || options.body);
if (req.body) {
xhr.send(req.body);
} else {
xhr.send(null);
}
return ret;
}
return ret;
};