HandlerFilter is analogous to the Servlet filter. This executes before the request gets processed by HandlerFunction. There could be chain filters that get executed before the request gets served. If a filter sends back a ServerResponse, then the request is terminated as follows:

helloRoute.filter((request, next) -> {    if (request.headers().acceptCharset().contains(Charset.forName("UTF-8"))) {        return next.handle(request);    }    else {        return ServerResponse.status(HttpStatus.BAD_REQUEST).build();    }});

The preceding code is doing the following:

  1. Adding a filter to helloRoute using the filter() method 
  2. The filter takes a request and the next handler function
  3. Validating whether or not the request headers contain the UTF-8 charset in ...

Get Hands-On Reactive Programming with Reactor now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.