From 19cbca0c714d06fe26e521759ceec27f4dda396a Mon Sep 17 00:00:00 2001 From: Harry Lachenmayer Date: Tue, 20 Oct 2015 19:49:56 +0100 Subject: [PATCH] Add HTTP basic authentication for Node. --- lib/adapters/http.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/adapters/http.js b/lib/adapters/http.js index 30e3ccc7ea..740a9dcbe7 100644 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -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