mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[minor] Move private methods to the bottom of file(s)
This commit is contained in:
parent
0e36912906
commit
ec03d72c5d
@ -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) {
|
||||
|
||||
@ -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();
|
||||
});
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user