User Buffer for base64 encoding and remove withCredentials.
This commit is contained in:
@ -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",
|
||||||
|
|||||||
12
src/lib/connectors/angular.js
vendored
12
src/lib/connectors/angular.js
vendored
@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user