Class UrlHandlerFilter

java.lang.Object
org.springframework.web.filter.reactive.UrlHandlerFilter
All Implemented Interfaces:
WebFilter

public final class UrlHandlerFilter extends Object implements WebFilter
WebFilter that modifies the URL, and then redirects or wraps the request to apply the change.

To create an instance, you can use the following:

 UrlHandlerFilter filter = UrlHandlerFilter
    .trailingSlashHandler("/path1/**").redirect(HttpStatus.PERMANENT_REDIRECT)
    .trailingSlashHandler("/path2/**").mutateRequest()
    .build();
 

This WebFilter should be ordered ahead of security filters.

Since:
6.2
Author:
Rossen Stoyanchev
  • Method Details

    • filter

      public reactor.core.publisher.Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain)
      Description copied from interface: WebFilter
      Process the Web request and (optionally) delegate to the next WebFilter through the given WebFilterChain.
      Specified by:
      filter in interface WebFilter
      Parameters:
      exchange - the current server exchange
      chain - provides a way to delegate to the next filter
      Returns:
      Mono<Void> to indicate when request processing is complete
    • trailingSlashHandler

      public static UrlHandlerFilter.Builder.TrailingSlashSpec trailingSlashHandler(String... pathPatterns)
      Create a builder by adding a handler for URL's with a trailing slash.
      Parameters:
      pathPatterns - path patterns to map the handler to, e.g. "/path/*", "/path/**", "/path/foo/".
      Returns:
      a spec to configure the trailing slash handler with
      See Also: