ENH: updated agent options in common.setupOutgoing

This commit is contained in:
srossross 2013-09-17 14:52:53 -07:00
parent f566a42e51
commit 12cda561af
2 changed files with 6 additions and 19 deletions

View File

@ -28,12 +28,10 @@ proxy.createProxyServer = function createProxyServer(options) {
" { ",
" target : <url string to be parsed with the url module> ",
" forward: <url string to be parsed with the url module> ",
" agent : <object to be passed to http(s).request(...)> ",
" agent : <object to be passed to http(s).request> ",
" ssl : <object to be passed to https.createServer()> ",
" ws : <true/false, if you want to proxy websockets> ",
" xfwd : <true/false, adds x-forward headers> ",
" maxSock: <maximum number of sockets> ",
" agent : <http agent for pooled connections> ",
" } ",
" ",
"NOTE: `options.ws` and `options.ssl` are optional. ",

View File

@ -1,8 +1,5 @@
var common = exports
, http = require('http')
, https = require('https')
, extend = require('util')._extend
;
var common = exports,
extend = require('util')._extend;
/**
* Copies the right headers from `options` and `req` to
@ -28,7 +25,7 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
outgoing.port = options[forward || 'target'].port ||
(~['https:', 'wss:'].indexOf(options[forward || 'target'].protocol) ? 443 : 80);
['host', 'hostname', 'socketPath', 'agent'].forEach(
['host', 'hostname', 'socketPath'].forEach(
function(e) { outgoing[e] = options[forward || 'target'][e]; }
);
@ -39,16 +36,8 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
if (options.headers){
extend(outgoing.headers, options.headers);
}
if (options.agent){
outgoing.agent = options.agent;
}
if (!outgoing.agent){
var Agent = (~['https:', 'wss:'].indexOf(options[forward || 'target'].protocol) ? https.Agent : http.Agent);
outgoing.agent = new Agent(options.maxSock || 100);
}
outgoing.agent = options.agent || false;
outgoing.path = req.url;
return outgoing;