@@ -1130,6 +1130,54 @@ describe('app.router', function(){
1130
1130
var app = express ( ) ;
1131
1131
assert . strictEqual ( app . get ( '/' , function ( ) { } ) , app )
1132
1132
} )
1133
+
1134
+ it ( 'should should not use disposed router/middleware' , function ( done ) {
1135
+ var app = express ( ) ;
1136
+ var router = new express . Router ( ) ;
1137
+
1138
+ router . use ( function ( req , res , next ) {
1139
+ res . setHeader ( 'old' , 'foo' ) ;
1140
+ next ( ) ;
1141
+ } ) ;
1142
+
1143
+ app . use ( function ( req , res , next ) {
1144
+ return router . handle ( req , res , next ) ;
1145
+ } ) ;
1146
+
1147
+ app . get ( '/' , function ( req , res , next ) {
1148
+ res . send ( 'yee' ) ;
1149
+ next ( ) ;
1150
+ } ) ;
1151
+
1152
+ request ( app )
1153
+ . get ( '/' )
1154
+ . expect ( 'old' , 'foo' )
1155
+ . expect ( function ( res ) {
1156
+ if ( typeof res . headers [ 'new' ] !== 'undefined' ) {
1157
+ throw new Error ( '`new` header should not be present' ) ;
1158
+ }
1159
+ } )
1160
+ . expect ( 200 , 'yee' , function ( err , res ) {
1161
+ if ( err ) return done ( err ) ;
1162
+
1163
+ router = new express . Router ( ) ;
1164
+
1165
+ router . use ( function ( req , res , next ) {
1166
+ res . setHeader ( 'new' , 'bar' ) ;
1167
+ next ( ) ;
1168
+ } ) ;
1169
+
1170
+ request ( app )
1171
+ . get ( '/' )
1172
+ . expect ( 'new' , 'bar' )
1173
+ . expect ( function ( res ) {
1174
+ if ( typeof res . headers [ 'old' ] !== 'undefined' ) {
1175
+ throw new Error ( '`old` header should not be present' ) ;
1176
+ }
1177
+ } )
1178
+ . expect ( 200 , 'yee' , done ) ;
1179
+ } ) ;
1180
+ } )
1133
1181
} )
1134
1182
1135
1183
function supportsRegexp ( source ) {
0 commit comments