Skip to content

Commit

Permalink
ENH: updated agent options in common.setupOutgoing
Browse files Browse the repository at this point in the history
  • Loading branch information
srossross committed Sep 17, 2013
1 parent f566a42 commit 12cda56
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
4 changes: 1 addition & 3 deletions lib/caronte.js
Original file line number Diff line number Diff line change
Expand Up @@ -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. ",
Expand Down
21 changes: 5 additions & 16 deletions lib/caronte/common.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]; }
);

Expand All @@ -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;
Expand Down

0 comments on commit 12cda56

Please sign in to comment.