Skip to content

Commit

Permalink
[minor] Move private methods to the bottom of file(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Sep 8, 2011
1 parent 0e36912 commit ec03d72
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 73 deletions.
2 changes: 1 addition & 1 deletion lib/node-http-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
144 changes: 72 additions & 72 deletions lib/node-http-proxy/http-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
});
};

0 comments on commit ec03d72

Please sign in to comment.