mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +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;
|
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
|
// Parse url
|
||||||
var parsed = url.parse(config.url);
|
var parsed = url.parse(config.url);
|
||||||
var options = {
|
var options = {
|
||||||
@@ -54,7 +62,8 @@ module.exports = function httpAdapter(resolve, reject, config) {
|
|||||||
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
|
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
|
||||||
method: config.method,
|
method: config.method,
|
||||||
headers: headers,
|
headers: headers,
|
||||||
agent: config.agent
|
agent: config.agent,
|
||||||
|
auth: auth
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create the request
|
// Create the request
|
||||||
|
|||||||
Reference in New Issue
Block a user