mirror of
https://github.com/tenrok/axios.git
synced 2026-05-30 15:24:11 +03:00
Add HTTP basic authentication for Node.
This commit is contained in:
committed by
Idan Gazit
parent
32a904394f
commit
19cbca0c71
+10
-1
@@ -46,6 +46,14 @@ module.exports = function httpAdapter(resolve, reject, config) {
|
||||
headers['Content-Length'] = data.length;
|
||||
}
|
||||
|
||||
// HTTP basic authentication
|
||||
var auth = undefined;
|
||||
if (config.auth) {
|
||||
var username = config.auth.user || config.auth.username;
|
||||
var password = config.auth.pass || config.auth.password;
|
||||
auth = username + ':' + password;
|
||||
}
|
||||
|
||||
// Parse url
|
||||
var parsed = url.parse(config.url);
|
||||
var options = {
|
||||
@@ -54,7 +62,8 @@ module.exports = function httpAdapter(resolve, reject, config) {
|
||||
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
|
||||
method: config.method,
|
||||
headers: headers,
|
||||
agent: config.agent
|
||||
agent: config.agent,
|
||||
auth: auth
|
||||
};
|
||||
|
||||
// Create the request
|
||||
|
||||
Reference in New Issue
Block a user