@@ -1156,6 +1156,56 @@ describe('app.router', function(){
11561156 var app = express ( ) ;
11571157 assert . strictEqual ( app . get ( '/' , function ( ) { } ) , app )
11581158 } )
1159+
1160+ it ( 'should should not use disposed router/middleware' , function ( done ) {
1161+ // more context: https://github.com/expressjs/express/issues/5743#issuecomment-2277148412
1162+
1163+ var app = express ( ) ;
1164+ var router = new express . Router ( ) ;
1165+
1166+ router . use ( function ( req , res , next ) {
1167+ res . setHeader ( 'old' , 'foo' ) ;
1168+ next ( ) ;
1169+ } ) ;
1170+
1171+ app . use ( function ( req , res , next ) {
1172+ return router . handle ( req , res , next ) ;
1173+ } ) ;
1174+
1175+ app . get ( '/' , function ( req , res , next ) {
1176+ res . send ( 'yee' ) ;
1177+ next ( ) ;
1178+ } ) ;
1179+
1180+ request ( app )
1181+ . get ( '/' )
1182+ . expect ( 'old' , 'foo' )
1183+ . expect ( function ( res ) {
1184+ if ( typeof res . headers [ 'new' ] !== 'undefined' ) {
1185+ throw new Error ( '`new` header should not be present' ) ;
1186+ }
1187+ } )
1188+ . expect ( 200 , 'yee' , function ( err , res ) {
1189+ if ( err ) return done ( err ) ;
1190+
1191+ router = new express . Router ( ) ;
1192+
1193+ router . use ( function ( req , res , next ) {
1194+ res . setHeader ( 'new' , 'bar' ) ;
1195+ next ( ) ;
1196+ } ) ;
1197+
1198+ request ( app )
1199+ . get ( '/' )
1200+ . expect ( 'new' , 'bar' )
1201+ . expect ( function ( res ) {
1202+ if ( typeof res . headers [ 'old' ] !== 'undefined' ) {
1203+ throw new Error ( '`old` header should not be present' ) ;
1204+ }
1205+ } )
1206+ . expect ( 200 , 'yee' , done ) ;
1207+ } ) ;
1208+ } )
11591209} )
11601210
11611211function supportsRegexp ( source ) {
0 commit comments