Skip to content

Commit 90fb01d

Browse files
committed
[fix] fixed options and server reference to can access them from passes functions
1 parent 1d1ee88 commit 90fb01d

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

lib/http-proxy/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function createRightProxy(type) {
7373
* refer to the connection socket
7474
* pass(req, socket, options, head)
7575
*/
76-
if(passes[i](req, res, cbl ? false : this, head, cbl)) { // passes can return a truthy value to halt the loop
76+
if(passes[i].call(this, req, res, head, cbl)) { // passes can return a truthy value to halt the loop
7777
break;
7878
}
7979
}

lib/http-proxy/passes/web-incoming.js

+18-13
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ web_o = Object.keys(web_o).map(function(pass) {
2323
*
2424
* @param {ClientRequest} Req Request object
2525
* @param {IncomingMessage} Res Response object
26-
* @param {Object} Options Config object passed to the proxy
2726
*
2827
* @api private
2928
*/
3029

31-
function deleteLength(req, res, options) {
30+
function deleteLength(req, res) {
31+
// Now the options are stored on this
32+
var options = this.options;
3233
if(req.method === 'DELETE' && !req.headers['content-length']) {
3334
req.headers['content-length'] = '0';
3435
}
@@ -39,12 +40,13 @@ web_o = Object.keys(web_o).map(function(pass) {
3940
*
4041
* @param {ClientRequest} Req Request object
4142
* @param {IncomingMessage} Res Response object
42-
* @param {Object} Options Config object passed to the proxy
4343
*
4444
* @api private
4545
*/
4646

47-
function timeout(req, res, options) {
47+
function timeout(req, res) {
48+
// Now the options are stored on this
49+
var options = this.options;
4850
if(options.timeout) {
4951
req.socket.setTimeout(options.timeout);
5052
}
@@ -55,12 +57,13 @@ web_o = Object.keys(web_o).map(function(pass) {
5557
*
5658
* @param {ClientRequest} Req Request object
5759
* @param {IncomingMessage} Res Response object
58-
* @param {Object} Options Config object passed to the proxy
5960
*
6061
* @api private
6162
*/
6263

63-
function XHeaders(req, res, options) {
64+
function XHeaders(req, res) {
65+
// Now the options are stored on this
66+
var options = this.options;
6467
if(!options.xfwd) return;
6568

6669
var values = {
@@ -84,24 +87,26 @@ web_o = Object.keys(web_o).map(function(pass) {
8487
*
8588
* @param {ClientRequest} Req Request object
8689
* @param {IncomingMessage} Res Response object
87-
* @param {Object} Options Config object passed to the proxy
8890
*
8991
* @api private
9092
*/
9193

92-
function stream(req, res, server, _, clb) {
93-
if(server.options.forward) {
94+
function stream(req, res, head, clb) {
95+
var server = this;
96+
// Now the options are stored on this
97+
var options = this.options;
98+
if(options.forward) {
9499
// If forward enable, so just pipe the request
95-
var forwardReq = (server.options.forward.protocol === 'https:' ? https : http).request(
96-
common.setupOutgoing(server.options.ssl || {}, server.options, req, 'forward')
100+
var forwardReq = (options.forward.protocol === 'https:' ? https : http).request(
101+
common.setupOutgoing(options.ssl || {}, options, req, 'forward')
97102
);
98103
req.pipe(forwardReq);
99104
return res.end();
100105
}
101106

102107
// Request initalization
103-
var proxyReq = (server.options.target.protocol === 'https:' ? https : http).request(
104-
common.setupOutgoing(server.options.ssl || {}, server.options, req)
108+
var proxyReq = (options.target.protocol === 'https:' ? https : http).request(
109+
common.setupOutgoing(options.ssl || {}, options, req)
105110
);
106111

107112
// Error Handler

0 commit comments

Comments
 (0)