public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
Flux<DataBuffer> body = exchange.getRequest().getBody();
//Return different according to body content...
if (condition) {
return chain.filter(exchange);
} else {
return Mono.empty();
}
}
How do I get the body of the request to do some custom judgments in spring-webflux with spring 5?
Your question is not entirely clear. I assume your doubt is what you put in the code snippet comments.
There are probably different ways to achieve what you want. One simple way to do it is by using a flatMap operator. Somewhat as follows:
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
Flux<DataBuffer> body = exchange.getRequest().getBody()
.flatMap(data -> {
if (condition) {
return chain.filter(exchange);
}
return Mono.empty();
});
//...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With