mirror of
https://github.com/tenrok/axios.git
synced 2026-05-30 15:24:11 +03:00
Fixing 245:
Formatting and adding tests
This commit is contained in:
@@ -47,10 +47,10 @@ module.exports = function httpAdapter(resolve, reject, config) {
|
||||
// Parse url
|
||||
var parsed = url.parse(config.url);
|
||||
if (!auth && parsed.auth) {
|
||||
var urlAuth = parsed.auth.split(":");
|
||||
var urlUsername = urlAuth[0] || "";
|
||||
var urlPassword = urlAuth[1] || "";
|
||||
auth = urlUsername + ':' + urlPassword;
|
||||
var urlAuth = parsed.auth.split(':');
|
||||
var urlUsername = urlAuth[0] || '';
|
||||
var urlPassword = urlAuth[1] || '';
|
||||
auth = urlUsername + ':' + urlPassword;
|
||||
}
|
||||
var options = {
|
||||
hostname: parsed.hostname,
|
||||
@@ -59,7 +59,7 @@ module.exports = function httpAdapter(resolve, reject, config) {
|
||||
method: config.method,
|
||||
headers: headers,
|
||||
agent: config.agent,
|
||||
auth: auth || parsed.auth,
|
||||
auth: auth
|
||||
};
|
||||
|
||||
// Create the request
|
||||
|
||||
@@ -113,5 +113,19 @@ module.exports = {
|
||||
test.done();
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
testBasicAuth: function (test) {
|
||||
server = http.createServer(function (req, res) {
|
||||
console.log(req.headers);
|
||||
res.end(req.headers.authorization);
|
||||
}).listen(4444, function () {
|
||||
var user = 'foo';
|
||||
axios.get('http://' + user + '@localhost:4444/').then(function (res) {
|
||||
var base64 = new Buffer(user + ':', 'utf8').toString('base64');
|
||||
test.equal(res.data, 'Basic ' + base64);
|
||||
test.done();
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user