Skip to content

Commit ec03d72

Browse files
committed
[minor] Move private methods to the bottom of file(s)
1 parent 0e36912 commit ec03d72

File tree

2 files changed

+73
-73
lines changed

2 files changed

+73
-73
lines changed

lib/node-http-proxy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ exports.createServer = function () {
153153
// __Attribution:__ This approach is based heavily on
154154
// [Connect](https://github.com/senchalabs/connect/blob/master/lib/utils.js#L157).
155155
// However, this is not a big leap from the implementation in node-http-proxy < 0.4.0.
156-
// This simply chooses to manage the scope of the events on a new Object literal as opposed to
156+
// This simply chooses to manage the scope of the events on a new Object literal as opposed to
157157
// [on the HttpProxy instance](https://github.com/nodejitsu/node-http-proxy/blob/v0.3.1/lib/node-http-proxy.js#L154).
158158
//
159159
exports.buffer = function (obj) {

lib/node-http-proxy/http-proxy.js

+72-72
Original file line numberDiff line numberDiff line change
@@ -323,78 +323,6 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
323323
}
324324
};
325325

326-
//
327-
// ### @private function _forwardRequest (req)
328-
// #### @req {ServerRequest} Incoming HTTP Request to proxy.
329-
// Forwards the specified `req` to the location specified
330-
// by `this.forward` ignoring errors and the subsequent response.
331-
//
332-
HttpProxy.prototype._forwardRequest = function (req) {
333-
var self = this,
334-
outgoing = new(this.forward.base),
335-
forwardProxy;
336-
337-
//
338-
// Setup outgoing proxy with relevant properties.
339-
//
340-
outgoing.host = this.forward.host;
341-
outgoing.port = this.forward.port,
342-
outgoing.agent = this.forward.agent;
343-
outgoing.method = req.method;
344-
outgoing.path = req.url;
345-
outgoing.headers = req.headers;
346-
347-
//
348-
// Open new HTTP request to internal resource with will
349-
// act as a reverse proxy pass.
350-
//
351-
forwardProxy = this.forward.protocol.request(outgoing, function (response) {
352-
//
353-
// Ignore the response from the forward proxy since this is a 'fire-and-forget' proxy.
354-
// Remark (indexzero): We will eventually emit a 'forward' event here for performance tuning.
355-
//
356-
});
357-
358-
//
359-
// Add a listener for the connection timeout event.
360-
//
361-
// Remark: Ignoring this error in the event
362-
// forward target doesn't exist.
363-
//
364-
forwardProxy.once('error', function (err) { });
365-
366-
//
367-
// Chunk the client request body as chunks from
368-
// the proxied request come in
369-
//
370-
req.on('data', function (chunk) {
371-
var flushed = forwardProxy.write(chunk);
372-
if (!flushed) {
373-
req.pause();
374-
forwardProxy.once('drain', function () {
375-
try { req.resume() }
376-
catch (er) { console.error("req.resume error: %s", er.message) }
377-
});
378-
379-
//
380-
// Force the `drain` event in 100ms if it hasn't
381-
// happened on its own.
382-
//
383-
setTimeout(function () {
384-
forwardProxy.emit('drain');
385-
}, 100);
386-
}
387-
});
388-
389-
//
390-
// At the end of the client request, we are going to
391-
// stop the proxied request
392-
//
393-
req.on('end', function () {
394-
forwardProxy.end();
395-
});
396-
};
397-
398326
//
399327
// ### function proxyWebSocketRequest (req, socket, head, buffer)
400328
// #### @req {ServerRequest} Websocket request to proxy.
@@ -733,3 +661,75 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
733661
: buffer.destroy();
734662
}
735663
};
664+
665+
//
666+
// ### @private function _forwardRequest (req)
667+
// #### @req {ServerRequest} Incoming HTTP Request to proxy.
668+
// Forwards the specified `req` to the location specified
669+
// by `this.forward` ignoring errors and the subsequent response.
670+
//
671+
HttpProxy.prototype._forwardRequest = function (req) {
672+
var self = this,
673+
outgoing = new(this.forward.base),
674+
forwardProxy;
675+
676+
//
677+
// Setup outgoing proxy with relevant properties.
678+
//
679+
outgoing.host = this.forward.host;
680+
outgoing.port = this.forward.port,
681+
outgoing.agent = this.forward.agent;
682+
outgoing.method = req.method;
683+
outgoing.path = req.url;
684+
outgoing.headers = req.headers;
685+
686+
//
687+
// Open new HTTP request to internal resource with will
688+
// act as a reverse proxy pass.
689+
//
690+
forwardProxy = this.forward.protocol.request(outgoing, function (response) {
691+
//
692+
// Ignore the response from the forward proxy since this is a 'fire-and-forget' proxy.
693+
// Remark (indexzero): We will eventually emit a 'forward' event here for performance tuning.
694+
//
695+
});
696+
697+
//
698+
// Add a listener for the connection timeout event.
699+
//
700+
// Remark: Ignoring this error in the event
701+
// forward target doesn't exist.
702+
//
703+
forwardProxy.once('error', function (err) { });
704+
705+
//
706+
// Chunk the client request body as chunks from
707+
// the proxied request come in
708+
//
709+
req.on('data', function (chunk) {
710+
var flushed = forwardProxy.write(chunk);
711+
if (!flushed) {
712+
req.pause();
713+
forwardProxy.once('drain', function () {
714+
try { req.resume() }
715+
catch (er) { console.error("req.resume error: %s", er.message) }
716+
});
717+
718+
//
719+
// Force the `drain` event in 100ms if it hasn't
720+
// happened on its own.
721+
//
722+
setTimeout(function () {
723+
forwardProxy.emit('drain');
724+
}, 100);
725+
}
726+
});
727+
728+
//
729+
// At the end of the client request, we are going to
730+
// stop the proxied request
731+
//
732+
req.on('end', function () {
733+
forwardProxy.end();
734+
});
735+
};

0 commit comments

Comments
 (0)