Skip to content

Commit

Permalink
Merge pull request #387 from rubennorte/feature/allow-http-and-https-…
Browse files Browse the repository at this point in the history
…agents

Replace 'agent' option with 'httpAgent' and 'httpsAgent'
  • Loading branch information
nickuraltsev committed Jul 25, 2016
2 parents 0578445 + f504dba commit 8332392
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,13 @@ These are the available config options for making requests. Only the `url` is re

// `maxRedirects` defines the maximum number of redirects to follow in node.js.
// If set to 0, no redirects will be followed.
maxRedirects: 5 // default
maxRedirects: 5, // default

// `httpAgent` and `httpsAgent` define a custom agent to be used when performing http
// and https requests, respectively, in node.js. This allows to configure options like
// `keepAlive` that are not enabled by default.
httpAgent: new http.Agent({ keepAlive: true }),
httpsAgent: new https.Agent({ keepAlive: true })
}
```

Expand Down
10 changes: 7 additions & 3 deletions lib/adapters/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,17 @@ module.exports = function httpAdapter(config) {
var urlPassword = urlAuth[1] || '';
auth = urlUsername + ':' + urlPassword;
}

var isHttps = parsed.protocol === 'https:';
var agent = isHttps ? config.httpsAgent : config.httpAgent;

var options = {
hostname: parsed.hostname,
port: parsed.port,
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
method: config.method,
headers: headers,
agent: config.agent,
agent: agent,
auth: auth
};

Expand All @@ -79,12 +83,12 @@ module.exports = function httpAdapter(config) {

var transport;
if (config.maxRedirects === 0) {
transport = parsed.protocol === 'https:' ? https : http;
transport = isHttps ? https : http;
} else {
if (config.maxRedirects) {
options.maxRedirects = config.maxRedirects;
}
transport = parsed.protocol === 'https:' ? httpsFollow : httpFollow;
transport = isHttps ? httpsFollow : httpFollow;
}

// Create the request
Expand Down

0 comments on commit 8332392

Please sign in to comment.