@@ -323,78 +323,6 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
323
323
}
324
324
} ;
325
325
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
-
398
326
//
399
327
// ### function proxyWebSocketRequest (req, socket, head, buffer)
400
328
// #### @req {ServerRequest} Websocket request to proxy.
@@ -733,3 +661,75 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
733
661
: buffer . destroy ( ) ;
734
662
}
735
663
} ;
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