@@ -1113,4 +1113,52 @@ describe('app.router', function(){
11131113    var  app  =  express ( ) ; 
11141114    assert . strictEqual ( app . get ( '/' ,  function  ( )  { } ) ,  app ) 
11151115  } ) 
1116+ 
1117+   it ( 'should should not use disposed router/middleware' ,  function ( done ) { 
1118+     var  app  =  express ( ) ; 
1119+     var  router  =  new  express . Router ( ) ; 
1120+ 
1121+     router . use ( function ( req ,  res ,  next ) { 
1122+       res . setHeader ( 'old' ,  'foo' ) ; 
1123+       next ( ) ; 
1124+     } ) ; 
1125+ 
1126+     app . use ( function  ( req ,  res ,  next )  { 
1127+       return  router . handle ( req ,  res ,  next ) ; 
1128+     } ) ; 
1129+ 
1130+     app . get ( '/' ,  function ( req ,  res ,  next ) { 
1131+       res . send ( 'yee' ) ; 
1132+       next ( ) ; 
1133+     } ) ; 
1134+ 
1135+     request ( app ) 
1136+     . get ( '/' ) 
1137+     . expect ( 'old' ,  'foo' ) 
1138+     . expect ( function ( res )  { 
1139+       if  ( typeof  res . headers [ 'new' ]  !==  'undefined' )  { 
1140+         throw  new  Error ( '`new` header should not be present' ) ; 
1141+       } 
1142+     } ) 
1143+     . expect ( 200 ,  'yee' ,  function ( err ,  res )  { 
1144+       if  ( err )  return  done ( err ) ; 
1145+ 
1146+       router  =  new  express . Router ( ) ; 
1147+ 
1148+       router . use ( function ( req ,  res ,  next ) { 
1149+         res . setHeader ( 'new' ,  'bar' ) ; 
1150+         next ( ) ; 
1151+       } ) ; 
1152+ 
1153+       request ( app ) 
1154+       . get ( '/' ) 
1155+       . expect ( 'new' ,  'bar' ) 
1156+       . expect ( function ( res )  { 
1157+         if  ( typeof  res . headers [ 'old' ]  !==  'undefined' )  { 
1158+           throw  new  Error ( '`old` header should not be present' ) ; 
1159+         } 
1160+       } ) 
1161+       . expect ( 200 ,  'yee' ,  done ) ; 
1162+     } ) ; 
1163+   } ) 
11161164} ) 
0 commit comments