Skip to content

Commit 13741a8

Browse files
committed
ENH: updated https and agent option
Removed logic from createProxyServer and put it into setupOutgoing. Conflicts: lib/caronte.js
1 parent f36cb4d commit 13741a8

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

lib/caronte.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ proxy.createProxyServer = function createProxyServer(options) {
2828
" { ",
2929
" target : <url string to be parsed with the url module> ",
3030
" forward: <url string to be parsed with the url module> ",
31+
" agent : <object to be passed to http(s).request(...)> ",
3132
" ssl : <object to be passed to https.createServer()> ",
3233
" ws : <true/false, if you want to proxy websockets> ",
3334
" xfwd : <true/false, adds x-forward headers> ",
@@ -41,14 +42,6 @@ proxy.createProxyServer = function createProxyServer(options) {
4142
].join("\n"));
4243
}
4344

44-
['target', 'forward'].forEach(function(key) {
45-
if(!options[key]) return;
46-
options[key] = url.parse(options[key]);
47-
48-
options[key].maxSockets = options.maxSock;
49-
options[key].agent = options.agent || false // new (options.ssl ? https.Agent : http.Agent)(options[key].maxSockets || 100);
50-
});
51-
5245
options.ee = new events.EventEmitter2({ wildcard: true, delimiter: ':' });
5346

5447
return {

lib/caronte/common.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
var common = exports;
1+
var common = exports
2+
, http = require('http')
3+
, https = require('https')
4+
;
25

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

38+
if (options.agent){
39+
outgoing.agent = options.agent;
40+
}
41+
42+
if (!outgoing.agent){
43+
var Agent = (~['https:', 'wss:'].indexOf(options[forward || 'target'].protocol) ? https.Agent : http.Agent);
44+
outgoing.agent = new Agent(options.maxSock || 100);
45+
}
46+
3547
outgoing.path = req.url;
3648

3749
return outgoing;

0 commit comments

Comments
 (0)