@@ -91,9 +91,7 @@ web_o = Object.keys(web_o).map(function(pass) {
91
91
92
92
function stream ( req , res , options , _ , server , clb ) {
93
93
94
- //
95
94
// And we begin!
96
- //
97
95
if ( ! clb ) {
98
96
server . emit ( 'start' , req , res , options . target )
99
97
}
@@ -111,14 +109,24 @@ web_o = Object.keys(web_o).map(function(pass) {
111
109
common . setupOutgoing ( options . ssl || { } , options , req )
112
110
) ;
113
111
112
+ // Ensure we abort proxy if request is aborted
113
+ req . on ( 'aborted' , function ( ) {
114
+ proxyReq . abort ( ) ;
115
+ } ) ;
116
+
117
+ // Handle errors on incoming request as well as it makes sense to
118
+ req . on ( 'error' , proxyError ) ;
119
+
114
120
// Error Handler
115
- proxyReq . on ( 'error' , function ( err ) {
121
+ proxyReq . on ( 'error' , proxyError ) ;
122
+
123
+ function proxyError ( err ) {
116
124
if ( clb ) {
117
125
clb ( err , req , res ) ;
118
126
} else {
119
127
server . emit ( 'error' , err , req , res ) ;
120
128
}
121
- } ) ;
129
+ }
122
130
123
131
( options . buffer || req ) . pipe ( proxyReq ) ;
124
132
@@ -128,9 +136,7 @@ web_o = Object.keys(web_o).map(function(pass) {
128
136
if ( web_o [ i ] ( req , res , proxyRes ) ) { break ; }
129
137
}
130
138
131
- //
132
139
// Allow us to listen when the proxy has completed
133
- //
134
140
proxyRes . on ( 'end' , function ( ) {
135
141
if ( ! clb ) {
136
142
server . emit ( 'end' , req , res , proxyRes ) ;
0 commit comments