paypro: clean up makeshift $http module.
This commit is contained in:
parent
8786fd9905
commit
04432aa426
1 changed files with 33 additions and 48 deletions
|
|
@ -1565,7 +1565,8 @@ Wallet.prototype.verifySignedJson = function(senderId, payload, signature) {
|
||||||
// NOTE: Angular $http module does not send ArrayBuffers correctly, so we're
|
// 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
|
// 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
|
// 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') {
|
// if (typeof angular !== 'undefined') {
|
||||||
// G.$http = G.$http || angular.bootstrap().get('$http');
|
// G.$http = G.$http || angular.bootstrap().get('$http');
|
||||||
// }
|
// }
|
||||||
|
|
@ -1600,59 +1601,43 @@ G.$http = G.$http || function $http(options, callback) {
|
||||||
var req = options;
|
var req = options;
|
||||||
|
|
||||||
req.headers = req.headers || {};
|
req.headers = req.headers || {};
|
||||||
req.body = req.body || {};
|
req.body = req.body || req.data || {};
|
||||||
|
|
||||||
if (typeof XMLHttpRequest !== 'undefined') {
|
var xhr = new XMLHttpRequest();
|
||||||
var xhr = new XMLHttpRequest();
|
xhr.open(method, uri, true);
|
||||||
xhr.open(method, uri, true);
|
|
||||||
|
|
||||||
Object.keys(options.headers).forEach(function(key) {
|
Object.keys(req.headers).forEach(function(key) {
|
||||||
var val = options.headers[key];
|
var val = req.headers[key];
|
||||||
if (key === 'Content-Length') return;
|
if (key === 'Content-Length') return;
|
||||||
if (key === 'Content-Transfer-Encoding') return;
|
if (key === 'Content-Transfer-Encoding') return;
|
||||||
xhr.setRequestHeader(key, val);
|
xhr.setRequestHeader(key, val);
|
||||||
});
|
});
|
||||||
|
|
||||||
// For older browsers (binary data):
|
if (req.responseType) {
|
||||||
// xhr.overrideMimeType('text/plain; charset=x-user-defined');
|
xhr.responseType = req.responseType;
|
||||||
|
}
|
||||||
|
|
||||||
// Newer browsers (binary data):
|
xhr.onload = function(event) {
|
||||||
// xhr.responseType = 'arraybuffer';
|
var response = xhr.response;
|
||||||
|
var buf = new Uint8Array(response);
|
||||||
|
var headers = {};
|
||||||
|
(xhr.getAllResponseHeaders() || '').replace(
|
||||||
|
/(?:\r?\n|^)([^:\r\n]+): *([^\r\n]+)/g,
|
||||||
|
function($0, $1, $2) {
|
||||||
|
headers[$1.toLowerCase()] = $2;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return ret._success(buf, xhr.status, headers, options);
|
||||||
|
};
|
||||||
|
|
||||||
if (options.responseType) {
|
xhr.onerror = function(event) {
|
||||||
xhr.responseType = options.responseType;
|
return ret._error(null, new Error(event.message), null, options);
|
||||||
}
|
};
|
||||||
|
|
||||||
// xhr.onreadystatechange = function() {
|
if (req.body) {
|
||||||
// if (xhr.readyState == 4) {
|
xhr.send(req.body);
|
||||||
// ;
|
} else {
|
||||||
// }
|
xhr.send(null);
|
||||||
// };
|
|
||||||
|
|
||||||
xhr.onload = function(event) {
|
|
||||||
var response = xhr.response;
|
|
||||||
var buf = new Uint8Array(response);
|
|
||||||
var headers = {};
|
|
||||||
(xhr.getAllResponseHeaders() || '').replace(
|
|
||||||
/(?:\r?\n|^)([^:\r\n]+): *([^\r\n]+)/g,
|
|
||||||
function($0, $1, $2) {
|
|
||||||
headers[$1.toLowerCase()] = $2;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return ret._success(buf, xhr.status, headers, options);
|
|
||||||
};
|
|
||||||
|
|
||||||
xhr.onerror = function(event) {
|
|
||||||
return ret._error(null, new Error(event.message), null, options);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (options.data || options.body) {
|
|
||||||
xhr.send(options.data || options.body);
|
|
||||||
} else {
|
|
||||||
xhr.send(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue