mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
Merge pull request #387 from rubennorte/feature/allow-http-and-https-agents
Replace 'agent' option with 'httpAgent' and 'httpsAgent'
This commit is contained in:
@@ -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.
|
// `maxRedirects` defines the maximum number of redirects to follow in node.js.
|
||||||
// If set to 0, no redirects will be followed.
|
// 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 })
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -61,13 +61,17 @@ module.exports = function httpAdapter(config) {
|
|||||||
var urlPassword = urlAuth[1] || '';
|
var urlPassword = urlAuth[1] || '';
|
||||||
auth = urlUsername + ':' + urlPassword;
|
auth = urlUsername + ':' + urlPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isHttps = parsed.protocol === 'https:';
|
||||||
|
var agent = isHttps ? config.httpsAgent : config.httpAgent;
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
hostname: parsed.hostname,
|
hostname: parsed.hostname,
|
||||||
port: parsed.port,
|
port: parsed.port,
|
||||||
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: agent,
|
||||||
auth: auth
|
auth: auth
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -79,12 +83,12 @@ module.exports = function httpAdapter(config) {
|
|||||||
|
|
||||||
var transport;
|
var transport;
|
||||||
if (config.maxRedirects === 0) {
|
if (config.maxRedirects === 0) {
|
||||||
transport = parsed.protocol === 'https:' ? https : http;
|
transport = isHttps ? https : http;
|
||||||
} else {
|
} else {
|
||||||
if (config.maxRedirects) {
|
if (config.maxRedirects) {
|
||||||
options.maxRedirects = config.maxRedirects;
|
options.maxRedirects = config.maxRedirects;
|
||||||
}
|
}
|
||||||
transport = parsed.protocol === 'https:' ? httpsFollow : httpFollow;
|
transport = isHttps ? httpsFollow : httpFollow;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the request
|
// Create the request
|
||||||
|
|||||||
Reference in New Issue
Block a user