@@ -281,6 +281,11 @@ describe('lib/http-proxy.js', function() {
281
281
client . send ( 'hello there' ) ;
282
282
} ) ;
283
283
284
+ client . on ( 'error' , function ( err ) {
285
+ expect ( err ) . to . be . an ( Error ) ;
286
+ expect ( err . code ) . to . be ( 'ECONNRESET' ) ;
287
+ } ) ;
288
+
284
289
proxy . on ( 'error' , function ( err ) {
285
290
expect ( err ) . to . be . an ( Error ) ;
286
291
expect ( err . code ) . to . be ( 'ECONNREFUSED' ) ;
@@ -289,6 +294,41 @@ describe('lib/http-proxy.js', function() {
289
294
} ) ;
290
295
} ) ;
291
296
297
+ it ( 'should close client socket if upstream is closed before upgrade' , function ( done ) {
298
+ var ports = { source : gen . port , proxy : gen . port } ;
299
+ var server = http . createServer ( ) ;
300
+ server . on ( 'upgrade' , function ( req , socket , head ) {
301
+ var response = [
302
+ 'HTTP/1.1 404 Not Found' ,
303
+ 'Content-type: text/html' ,
304
+ '' ,
305
+ ''
306
+ ] ;
307
+ socket . write ( response . join ( '\r\n' ) ) ;
308
+ socket . end ( ) ;
309
+ } ) ;
310
+ server . listen ( ports . source ) ;
311
+
312
+ var proxy = httpProxy . createProxyServer ( {
313
+ // note: we don't ever listen on this port
314
+ target : 'ws://127.0.0.1:' + ports . source ,
315
+ ws : true
316
+ } ) ,
317
+ proxyServer = proxy . listen ( ports . proxy ) ,
318
+ client = new ws ( 'ws://127.0.0.1:' + ports . proxy ) ;
319
+
320
+ client . on ( 'open' , function ( ) {
321
+ client . send ( 'hello there' ) ;
322
+ } ) ;
323
+
324
+ client . on ( 'error' , function ( err ) {
325
+ expect ( err ) . to . be . an ( Error ) ;
326
+ expect ( err . code ) . to . be ( 'ECONNRESET' ) ;
327
+ proxyServer . close ( ) ;
328
+ done ( ) ;
329
+ } ) ;
330
+ } ) ;
331
+
292
332
it ( 'should proxy a socket.io stream' , function ( done ) {
293
333
var ports = { source : gen . port , proxy : gen . port } ;
294
334
var proxy = httpProxy . createProxyServer ( {
0 commit comments