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) {
12651265 return this .routerFunction .route (nestedRequest )
12661266 .doOnNext (match -> {
12671267 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 );
12711275 }
12721276 });
12731277 }
Original file line number Diff line number Diff line change @@ -1181,8 +1181,13 @@ public Optional<HandlerFunction<T>> route(ServerRequest serverRequest) {
11811181 Optional <HandlerFunction <T >> result =
11821182 this .routerFunction .route (nestedRequest );
11831183 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 );
11861191 }
11871192 return result ;
11881193 }
You can’t perform that action at this time.
0 commit comments