File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed
spring-webflux/src/main/java/org/springframework/web/reactive/function/server
spring-webmvc/src/main/java/org/springframework/web/servlet/function Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -1265,9 +1265,13 @@ public Mono<HandlerFunction<T>> route(ServerRequest serverRequest) {
1265
1265
return this .routerFunction .route (nestedRequest )
1266
1266
.doOnNext (match -> {
1267
1267
if (nestedRequest != serverRequest ) {
1268
- serverRequest .attributes ().clear ();
1269
- serverRequest .attributes ()
1270
- .putAll (nestedRequest .attributes ());
1268
+ // new attributes map from nestedRequest.attributes() can be composed of the old attributes,
1269
+ // which means that clearing the old attributes will remove those values from new attributes as well
1270
+ // so let's make a copy
1271
+ Map <String , Object > newAttributes = new LinkedHashMap <>(nestedRequest .attributes ());
1272
+ Map <String , Object > oldAttributes = serverRequest .attributes ();
1273
+ oldAttributes .clear ();
1274
+ oldAttributes .putAll (newAttributes );
1271
1275
}
1272
1276
});
1273
1277
}
Original file line number Diff line number Diff line change @@ -1181,8 +1181,13 @@ public Optional<HandlerFunction<T>> route(ServerRequest serverRequest) {
1181
1181
Optional <HandlerFunction <T >> result =
1182
1182
this .routerFunction .route (nestedRequest );
1183
1183
if (result .isPresent () && nestedRequest != serverRequest ) {
1184
- serverRequest .attributes ().clear ();
1185
- serverRequest .attributes ().putAll (nestedRequest .attributes ());
1184
+ // new attributes map from nestedRequest.attributes() can be composed of the old attributes,
1185
+ // which means that clearing the old attributes will remove those values from new attributes as well
1186
+ // so let's make a copy
1187
+ Map <String , Object > newAttributes = new LinkedHashMap <>(nestedRequest .attributes ());
1188
+ Map <String , Object > oldAttributes = serverRequest .attributes ();
1189
+ oldAttributes .clear ();
1190
+ oldAttributes .putAll (newAttributes );
1186
1191
}
1187
1192
return result ;
1188
1193
}
You can’t perform that action at this time.
0 commit comments