1

With the "traditional" web framework, one could use e.g. AbstractRequestLoggingFilter for implementing a generic logging filter. With web-reactive the filter isn't called anymore (what makes sense, since it operates on HttpServletRequest).

Can anyone point me into the right direction for implementing a request filter with web-reactive, which logs the HTTP request, including its body, before and after the request like in AbstractRequestLoggingFilter?

Brian Clozel
  • 56,583
  • 15
  • 167
  • 176
nonpolar
  • 55
  • 5

1 Answers1

2

You can implement a WebFilter and declare it as a bean, it will be picked up automatically.

Note that the WebFilter contract is based on ServerWebExchange, which holds a ServerHttpRequest. The body is not accessible directly as byte[], but rather as a Flux<DataBuffer>; this is not meant to be buffered in memory or consumed by the filter, so logging the whole request body is more complex than in MVC scenarios. Also, you should avoid blocking operations during request processing.

Brian Clozel
  • 56,583
  • 15
  • 167
  • 176