add SSL configuration options

This commit is contained in:
Spencer Alger
2015-01-05 12:56:48 -07:00
parent 38828673ab
commit 4fc1c91634
5 changed files with 39 additions and 8 deletions

View File

@ -14,7 +14,7 @@ var handles = {
};
var _ = require('../utils');
var qs = require('querystring');
var ForeverAgent = require('./_custom_agent');
var KeepAliveAgent = require('./_keep_alive_agent');
var ConnectionAbstract = require('../connection');
var zlib = require('zlib');
@ -34,6 +34,8 @@ function HttpConnector(host, config) {
'", expected one of ' + _.keys(handles).join(', '));
}
this.useSsl = this.host.protocol === 'https';
config = _.defaults(config || {}, {
keepAlive: true,
minSockets: 10,
@ -77,7 +79,7 @@ HttpConnector.prototype.createAgent = function (config) {
}
if (config.keepAlive) {
Agent = this.host.protocol === 'https' ? ForeverAgent.SSL : ForeverAgent;
Agent = this.useSsl ? KeepAliveAgent.SSL : KeepAliveAgent;
this.on('status set', this.bound.onStatusSet);
}
@ -85,10 +87,16 @@ HttpConnector.prototype.createAgent = function (config) {
};
HttpConnector.prototype.makeAgentConfig = function (config) {
return {
var agentConfig = {
maxSockets: config.maxSockets,
minSockets: config.minSockets
};
if (this.useSsl) {
_.merge(agentConfig, this.host.ssl);
}
return agentConfig;
};
HttpConnector.prototype.makeReqParams = function (params) {

View File

@ -23,6 +23,17 @@ var urlParseFields = [
var simplify = ['host', 'path'];
var sslDefaults = {
pfx: null,
key: null,
passphrase: null,
cert: null,
ca: null,
ciphers: null,
rejectUnauthorized: false,
secureProtocol: null
};
// simple reference used when formatting as a url
// and defines when parsing from a string
Host.defaultPorts = {
@ -44,6 +55,8 @@ function Host(config, globalConfig) {
this.headers = null;
this.suggestCompression = !!globalConfig.suggestCompression;
this.ssl = _.defaults({}, config.ssl || {}, globalConfig.ssl || {}, sslDefaults);
if (typeof config === 'string') {
var firstColon = config.indexOf(':');
var firstSlash = config.indexOf('/');