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

This reverts commit 90fb01d38ac5af7ef395547b24e985b6f63b4abc.
This commit is contained in:
cronopio 2013-10-21 14:45:03 -05:00
parent 2bf20d61d5
commit babdf531fe
2 changed files with 14 additions and 19 deletions

View File

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

View File

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