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",
"forever-agent": "~0.5.2",
"lodash-node": "~2.3.0",
"when": "~2.6.0",
"js-base64": "~2.1.2"
"when": "~2.6.0"
},
"repository": {
"type": "git",

View File

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