Skip to content

Commit

Permalink
Add HTTP basic authentication for Node.
Browse files Browse the repository at this point in the history
  • Loading branch information
lachenmayer authored and idan committed Dec 9, 2015
1 parent 32a9043 commit 19cbca0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/adapters/http.js
Expand Up @@ -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 = {
Expand All @@ -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
Expand Down

0 comments on commit 19cbca0

Please sign in to comment.