Unify auth handling in the Host class

- flatten auth config to an Authorization header when the Host is created
 - remove individual Authorization handling from connectors
 - removed incomplete support for per-request auth
 - use per-request headers to provide your own Authorization header per request
This commit is contained in:
Spencer Alger
2015-04-08 15:05:51 -07:00
parent 8b59530eed
commit 7f468d2064
10 changed files with 40 additions and 103 deletions

View File

@ -53,16 +53,21 @@ if (!getXhr) {
XhrConnector.prototype.request = function (params, cb) {
var xhr = getXhr();
var timeoutId;
var url = this.host.makeUrl(params);
var headers = this.host.getHeaders(params.headers);
var host = this.host;
var log = this.log;
var url = host.makeUrl(params);
var headers = host.getHeaders(params.headers);
var async = params.async === false ? false : asyncDefault;
if (params.auth) {
xhr.open(params.method || 'GET', url, async, params.auth.user, params.auth.pass);
} else {
xhr.open(params.method || 'GET', url, async);
xhr.open(params.method || 'GET', url, async);
if (headers) {
for (var key in headers) {
if (headers[key] !== void 0) {
xhr.setRequestHeader(key, headers[key]);
}
}
}
xhr.onreadystatechange = function () {
@ -74,14 +79,6 @@ XhrConnector.prototype.request = function (params, cb) {
}
};
if (headers) {
for (var key in headers) {
if (headers[key] !== void 0) {
xhr.setRequestHeader(key, headers[key]);
}
}
}
xhr.send(params.body || void 0);
return function () {