Skip to content

Commit

Permalink
ENH: updated https and agent option
Browse files Browse the repository at this point in the history
Removed logic from createProxyServer and put it into setupOutgoing.

Conflicts:
	lib/caronte.js
  • Loading branch information
srossross committed Sep 17, 2013
1 parent f36cb4d commit 13741a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
9 changes: 1 addition & 8 deletions lib/caronte.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ 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(...)> ",
" ssl : <object to be passed to https.createServer()> ",
" ws : <true/false, if you want to proxy websockets> ",
" xfwd : <true/false, adds x-forward headers> ",
Expand All @@ -41,14 +42,6 @@ proxy.createProxyServer = function createProxyServer(options) {
].join("\n"));
}

['target', 'forward'].forEach(function(key) {
if(!options[key]) return;
options[key] = url.parse(options[key]);

options[key].maxSockets = options.maxSock;
options[key].agent = options.agent || false // new (options.ssl ? https.Agent : http.Agent)(options[key].maxSockets || 100);
});

options.ee = new events.EventEmitter2({ wildcard: true, delimiter: ':' });

return {
Expand Down
14 changes: 13 additions & 1 deletion lib/caronte/common.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
var common = exports;
var common = exports
, http = require('http')
, https = require('https')
;

/**
* Copies the right headers from `options` and `req` to
Expand Down Expand Up @@ -32,6 +35,15 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
function(e) { outgoing[e] = req[e]; }
);

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.path = req.url;

return outgoing;
Expand Down

0 comments on commit 13741a8

Please sign in to comment.