Skip to content

Commit a7b16eb

Browse files
committed
[api] add toProxy method to allow absolute URLs to be sent when sending to another proxy fixes #603
1 parent c22610a commit a7b16eb

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/http-proxy.js

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ module.exports.createProxyServer = module.exports.createServer = function create
4242
* ws : <true/false, if you want to proxy websockets>
4343
* xfwd : <true/false, adds x-forward headers>
4444
* secure : <true/false, verify SSL certificate>
45+
* toProxy: <true/false, explicitly specify if we are proxying to another proxy
4546
* }
4647
*
4748
* NOTE: `options.ws` and `options.ssl` are optional.

lib/http-proxy/common.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
4444

4545

4646
outgoing.agent = options.agent || false;
47-
outgoing.path = url.parse(req.url).path;
47+
48+
//
49+
// Remark: Can we somehow not use url.parse as a perf optimization?
50+
//
51+
outgoing.path = !options.toProxy
52+
? url.parse(req.url).path
53+
: req.url;
54+
4855
return outgoing;
4956
};
5057

@@ -76,7 +83,7 @@ common.setupSocket = function(socket) {
7683

7784
common.getPort = function(req) {
7885
var res = req.headers.host ? req.headers.host.match(/:(\d+)/) : "";
79-
return res ?
86+
return res ?
8087
res[1] :
81-
req.connection.pair ? '443' : '80' ;
88+
req.connection.pair ? '443' : '80' ;
8289
}

0 commit comments

Comments
 (0)