@@ -344,6 +344,13 @@ HttpProxy.prototype.buffer = function (obj) {
344
344
obj . removeListener ( 'data' , onData ) ;
345
345
obj . removeListener ( 'end' , onEnd ) ;
346
346
} ,
347
+ destroy : function ( ) {
348
+ this . end ( ) ;
349
+ this . resume = function ( ) {
350
+ console . error ( "Cannot resume buffer after destroying it." ) ;
351
+ } ;
352
+ onData = onEnd = events = obj = null ;
353
+ } ,
347
354
resume : function ( ) {
348
355
this . end ( ) ;
349
356
for ( var i = 0 , len = events . length ; i < len ; ++ i ) {
@@ -586,8 +593,12 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
586
593
} ) ;
587
594
588
595
// If we have been passed buffered data, resume it.
589
- if ( options . buffer && ! errState ) {
590
- options . buffer . resume ( ) ;
596
+ if ( options . buffer ) {
597
+ if ( ! errState ) {
598
+ options . buffer . resume ( ) ;
599
+ } else {
600
+ options . buffer . destroy ( ) ;
601
+ }
591
602
}
592
603
} ;
593
604
@@ -733,6 +744,7 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
733
744
reverseProxy . incoming . socket . write ( data ) ;
734
745
}
735
746
catch ( e ) {
747
+ detach ( ) ;
736
748
reverseProxy . incoming . socket . end ( ) ;
737
749
proxySocket . end ( ) ;
738
750
}
@@ -749,6 +761,7 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
749
761
proxySocket . write ( data ) ;
750
762
}
751
763
catch ( e ) {
764
+ detach ( ) ;
752
765
proxySocket . end ( ) ;
753
766
socket . end ( ) ;
754
767
}
@@ -833,7 +846,6 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
833
846
if ( self . emit ( 'webSocketProxyError' , req , socket , head ) ) {
834
847
return ;
835
848
}
836
-
837
849
socket . end ( ) ;
838
850
}
839
851
@@ -932,10 +944,12 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
932
944
proxyError ( ex ) ;
933
945
}
934
946
935
- //
936
947
// If we have been passed buffered data, resume it.
937
- //
938
- if ( options . buffer && ! errState ) {
939
- options . buffer . resume ( ) ;
948
+ if ( options . buffer ) {
949
+ if ( ! errState ) {
950
+ options . buffer . resume ( ) ;
951
+ } else {
952
+ options . buffer . destroy ( ) ;
953
+ }
940
954
}
941
955
} ;
0 commit comments