Improve attribute handling in RequestPredicates
This commit changes the way request attributes are handled in RequestPredicates. Previously, the AND/OR/NOT predicates copied all attributes in a map, and restored that when the delegate predicate(s) failed. Now, we only set the attributes when all delegates have succeeded. Closes gh-30028
This commit is contained in:
committed by
Arjen Poutsma
parent
ed172d6269
commit
39786e4790
@@ -23,6 +23,8 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.codec.StringDecoder;
|
||||
import org.springframework.http.codec.DecoderHttpMessageReader;
|
||||
import org.springframework.web.reactive.function.server.RequestPredicates.Evaluation;
|
||||
import org.springframework.web.reactive.function.server.RequestPredicates.EvaluatorRequestPredicate;
|
||||
import org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest;
|
||||
import org.springframework.web.testfixture.server.MockServerWebExchange;
|
||||
|
||||
@@ -182,7 +184,7 @@ public class RequestPredicateAttributesTests {
|
||||
}
|
||||
|
||||
|
||||
private static class AddAttributePredicate implements RequestPredicate {
|
||||
private static class AddAttributePredicate extends EvaluatorRequestPredicate {
|
||||
|
||||
private boolean result;
|
||||
|
||||
@@ -197,9 +199,13 @@ public class RequestPredicateAttributesTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(ServerRequest request) {
|
||||
request.attributes().put(key, value);
|
||||
return this.result;
|
||||
public Evaluation apply(ServerRequest request) {
|
||||
return new Evaluation(result) {
|
||||
@Override
|
||||
void doCommit() {
|
||||
request.attributes().put(key, value);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user