[fix] fixed options and server reference to can access them from passes functions

This commit is contained in:
cronopio 2013-10-21 03:26:54 -05:00
parent 1d1ee88582
commit 90fb01d38a
2 changed files with 19 additions and 14 deletions

View File

@ -73,7 +73,7 @@ function createRightProxy(type) {
* refer to the connection socket * refer to the connection socket
* pass(req, socket, options, head) * pass(req, socket, options, head)
*/ */
if(passes[i](req, res, cbl ? false : this, head, cbl)) { // passes can return a truthy value to halt the loop if(passes[i].call(this, req, res, head, cbl)) { // passes can return a truthy value to halt the loop
break; break;
} }
} }

View File

@ -23,12 +23,13 @@ web_o = Object.keys(web_o).map(function(pass) {
* *
* @param {ClientRequest} Req Request object * @param {ClientRequest} Req Request object
* @param {IncomingMessage} Res Response object * @param {IncomingMessage} Res Response object
* @param {Object} Options Config object passed to the proxy
* *
* @api private * @api private
*/ */
function deleteLength(req, res, options) { function deleteLength(req, res) {
// Now the options are stored on this
var options = this.options;
if(req.method === 'DELETE' && !req.headers['content-length']) { if(req.method === 'DELETE' && !req.headers['content-length']) {
req.headers['content-length'] = '0'; req.headers['content-length'] = '0';
} }
@ -39,12 +40,13 @@ web_o = Object.keys(web_o).map(function(pass) {
* *
* @param {ClientRequest} Req Request object * @param {ClientRequest} Req Request object
* @param {IncomingMessage} Res Response object * @param {IncomingMessage} Res Response object
* @param {Object} Options Config object passed to the proxy
* *
* @api private * @api private
*/ */
function timeout(req, res, options) { function timeout(req, res) {
// Now the options are stored on this
var options = this.options;
if(options.timeout) { if(options.timeout) {
req.socket.setTimeout(options.timeout); req.socket.setTimeout(options.timeout);
} }
@ -55,12 +57,13 @@ web_o = Object.keys(web_o).map(function(pass) {
* *
* @param {ClientRequest} Req Request object * @param {ClientRequest} Req Request object
* @param {IncomingMessage} Res Response object * @param {IncomingMessage} Res Response object
* @param {Object} Options Config object passed to the proxy
* *
* @api private * @api private
*/ */
function XHeaders(req, res, options) { function XHeaders(req, res) {
// Now the options are stored on this
var options = this.options;
if(!options.xfwd) return; if(!options.xfwd) return;
var values = { var values = {
@ -84,24 +87,26 @@ web_o = Object.keys(web_o).map(function(pass) {
* *
* @param {ClientRequest} Req Request object * @param {ClientRequest} Req Request object
* @param {IncomingMessage} Res Response object * @param {IncomingMessage} Res Response object
* @param {Object} Options Config object passed to the proxy
* *
* @api private * @api private
*/ */
function stream(req, res, server, _, clb) { function stream(req, res, head, clb) {
if(server.options.forward) { var server = this;
// Now the options are stored on this
var options = this.options;
if(options.forward) {
// If forward enable, so just pipe the request // If forward enable, so just pipe the request
var forwardReq = (server.options.forward.protocol === 'https:' ? https : http).request( var forwardReq = (options.forward.protocol === 'https:' ? https : http).request(
common.setupOutgoing(server.options.ssl || {}, server.options, req, 'forward') common.setupOutgoing(options.ssl || {}, options, req, 'forward')
); );
req.pipe(forwardReq); req.pipe(forwardReq);
return res.end(); return res.end();
} }
// Request initalization // Request initalization
var proxyReq = (server.options.target.protocol === 'https:' ? https : http).request( var proxyReq = (options.target.protocol === 'https:' ? https : http).request(
common.setupOutgoing(server.options.ssl || {}, server.options, req) common.setupOutgoing(options.ssl || {}, options, req)
); );
// Error Handler // Error Handler