From ec03d72c5d8749aee835f571869f69816be02265 Mon Sep 17 00:00:00 2001 From: indexzero Date: Thu, 8 Sep 2011 16:53:42 -0700 Subject: [PATCH] [minor] Move private methods to the bottom of file(s) --- lib/node-http-proxy.js | 2 +- lib/node-http-proxy/http-proxy.js | 144 +++++++++++++++--------------- 2 files changed, 73 insertions(+), 73 deletions(-) diff --git a/lib/node-http-proxy.js b/lib/node-http-proxy.js index ea05ab1..4769312 100644 --- a/lib/node-http-proxy.js +++ b/lib/node-http-proxy.js @@ -153,7 +153,7 @@ exports.createServer = function () { // __Attribution:__ This approach is based heavily on // [Connect](https://github.com/senchalabs/connect/blob/master/lib/utils.js#L157). // However, this is not a big leap from the implementation in node-http-proxy < 0.4.0. -// This simply chooses to manage the scope of the events on a new Object literal as opposed to +// This simply chooses to manage the scope of the events on a new Object literal as opposed to // [on the HttpProxy instance](https://github.com/nodejitsu/node-http-proxy/blob/v0.3.1/lib/node-http-proxy.js#L154). // exports.buffer = function (obj) { diff --git a/lib/node-http-proxy/http-proxy.js b/lib/node-http-proxy/http-proxy.js index fd94d82..f288d3e 100644 --- a/lib/node-http-proxy/http-proxy.js +++ b/lib/node-http-proxy/http-proxy.js @@ -323,78 +323,6 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) { } }; -// -// ### @private function _forwardRequest (req) -// #### @req {ServerRequest} Incoming HTTP Request to proxy. -// Forwards the specified `req` to the location specified -// by `this.forward` ignoring errors and the subsequent response. -// -HttpProxy.prototype._forwardRequest = function (req) { - var self = this, - outgoing = new(this.forward.base), - forwardProxy; - - // - // Setup outgoing proxy with relevant properties. - // - outgoing.host = this.forward.host; - outgoing.port = this.forward.port, - outgoing.agent = this.forward.agent; - outgoing.method = req.method; - outgoing.path = req.url; - outgoing.headers = req.headers; - - // - // Open new HTTP request to internal resource with will - // act as a reverse proxy pass. - // - forwardProxy = this.forward.protocol.request(outgoing, function (response) { - // - // Ignore the response from the forward proxy since this is a 'fire-and-forget' proxy. - // Remark (indexzero): We will eventually emit a 'forward' event here for performance tuning. - // - }); - - // - // Add a listener for the connection timeout event. - // - // Remark: Ignoring this error in the event - // forward target doesn't exist. - // - forwardProxy.once('error', function (err) { }); - - // - // Chunk the client request body as chunks from - // the proxied request come in - // - req.on('data', function (chunk) { - var flushed = forwardProxy.write(chunk); - if (!flushed) { - req.pause(); - forwardProxy.once('drain', function () { - try { req.resume() } - catch (er) { console.error("req.resume error: %s", er.message) } - }); - - // - // Force the `drain` event in 100ms if it hasn't - // happened on its own. - // - setTimeout(function () { - forwardProxy.emit('drain'); - }, 100); - } - }); - - // - // At the end of the client request, we are going to - // stop the proxied request - // - req.on('end', function () { - forwardProxy.end(); - }); -}; - // // ### function proxyWebSocketRequest (req, socket, head, buffer) // #### @req {ServerRequest} Websocket request to proxy. @@ -733,3 +661,75 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer) : buffer.destroy(); } }; + +// +// ### @private function _forwardRequest (req) +// #### @req {ServerRequest} Incoming HTTP Request to proxy. +// Forwards the specified `req` to the location specified +// by `this.forward` ignoring errors and the subsequent response. +// +HttpProxy.prototype._forwardRequest = function (req) { + var self = this, + outgoing = new(this.forward.base), + forwardProxy; + + // + // Setup outgoing proxy with relevant properties. + // + outgoing.host = this.forward.host; + outgoing.port = this.forward.port, + outgoing.agent = this.forward.agent; + outgoing.method = req.method; + outgoing.path = req.url; + outgoing.headers = req.headers; + + // + // Open new HTTP request to internal resource with will + // act as a reverse proxy pass. + // + forwardProxy = this.forward.protocol.request(outgoing, function (response) { + // + // Ignore the response from the forward proxy since this is a 'fire-and-forget' proxy. + // Remark (indexzero): We will eventually emit a 'forward' event here for performance tuning. + // + }); + + // + // Add a listener for the connection timeout event. + // + // Remark: Ignoring this error in the event + // forward target doesn't exist. + // + forwardProxy.once('error', function (err) { }); + + // + // Chunk the client request body as chunks from + // the proxied request come in + // + req.on('data', function (chunk) { + var flushed = forwardProxy.write(chunk); + if (!flushed) { + req.pause(); + forwardProxy.once('drain', function () { + try { req.resume() } + catch (er) { console.error("req.resume error: %s", er.message) } + }); + + // + // Force the `drain` event in 100ms if it hasn't + // happened on its own. + // + setTimeout(function () { + forwardProxy.emit('drain'); + }, 100); + } + }); + + // + // At the end of the client request, we are going to + // stop the proxied request + // + req.on('end', function () { + forwardProxy.end(); + }); +}; \ No newline at end of file