User Buffer for base64 encoding and remove withCredentials.

This commit is contained in:
Jeff French
2014-02-13 20:02:40 -06:00
parent 4a598f5276
commit 90559ead06
2 changed files with 5 additions and 10 deletions

View File

@ -69,8 +69,7 @@
"chalk": "~0.3.0", "chalk": "~0.3.0",
"forever-agent": "~0.5.2", "forever-agent": "~0.5.2",
"lodash-node": "~2.3.0", "lodash-node": "~2.3.0",
"when": "~2.6.0", "when": "~2.6.0"
"js-base64": "~2.1.2"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -9,30 +9,26 @@ module.exports = AngularConnector;
var _ = require('../utils'); var _ = require('../utils');
var ConnectionAbstract = require('../connection'); var ConnectionAbstract = require('../connection');
var ConnectionFault = require('../errors').ConnectionFault; var ConnectionFault = require('../errors').ConnectionFault;
var base64 = require('js-base64').Base64;
function AngularConnector(host, config) { function AngularConnector(host, config) {
ConnectionAbstract.call(this, host, config); ConnectionAbstract.call(this, host, config);
this.defer = config.defer; this.defer = config.defer;
this.$http = config.$http; this.$http = config.$http;
if(this.host.auth) {
this.$http.defaults.headers.common.Authorization = 'Basic ' + Buffer(this.host.auth, 'utf8').toString('base64');
}
} }
_.inherits(AngularConnector, ConnectionAbstract); _.inherits(AngularConnector, ConnectionAbstract);
AngularConnector.prototype.request = function (params, cb) { AngularConnector.prototype.request = function (params, cb) {
var abort = this.defer(); var abort = this.defer();
var headers = {};
if(this.host.auth) {
headers['Authorization'] = 'Basic ' + base64.encode(this.host.auth);
}
this.$http({ this.$http({
method: params.method, method: params.method,
url: this.host.makeUrl(params), url: this.host.makeUrl(params),
data: params.body, data: params.body,
cache: false, cache: false,
transformRequest: [], transformRequest: [],
transformResponse: [], transformResponse: []
headers: headers,
withCredentials: !!this.host.auth
}).then(function (response) { }).then(function (response) {
cb(null, response.data, response.status, response.headers()); cb(null, response.data, response.status, response.headers());
}, function (err) { }, function (err) {