org.springframework.web.reactive.resource

## Class PathResourceResolver

- java.lang.Object
- - org.springframework.web.reactive.resource.AbstractResourceResolver
  - - org.springframework.web.reactive.resource.PathResourceResolver

- All Implemented Interfaces:
    ResourceResolver

      public class PathResourceResolver
      extends AbstractResourceResolver

  A simple `ResourceResolver` that tries to find a resource under the given locations matching to the request path.

  This resolver does not delegate to the `ResourceResolverChain` and is expected to be configured at the end in a chain of resolvers.

  Since:
    5.0
  Author:
    Rossen Stoyanchev

- - ### Field Summary

    - ### Fields inherited from class org.springframework.web.reactive.resource.AbstractResourceResolver

      `logger`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PathResourceResolver()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected boolean` | `checkResource(Resource resource, Resource location)` Perform additional checks on a resolved resource beyond checking whether the resource exists and is readable.
    `Resource[]` | `getAllowedLocations()`
    `protected reactor.core.publisher.Mono<Resource>` | `getResource(String resourcePath, Resource location)` Find the resource under the given location.
    `protected reactor.core.publisher.Mono<Resource>` | `resolveResourceInternal(ServerWebExchange exchange, String requestPath, List<? extends Resource> locations, ResourceResolverChain chain)`
    `protected reactor.core.publisher.Mono<String>` | `resolveUrlPathInternal(String path, List<? extends Resource> locations, ResourceResolverChain chain)`
    `void` | `setAllowedLocations(Resource... locations)` By default, when a Resource is found, the path of the resolved resource is compared to ensure it's under the input location where it was found.

    - ### Methods inherited from class org.springframework.web.reactive.resource.AbstractResourceResolver

      `resolveResource, resolveUrlPath`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### PathResourceResolver

          public PathResourceResolver()

  - ### Method Detail

    - #### setAllowedLocations

          public void setAllowedLocations(@Nullable
                                          Resource... locations)

      By default, when a Resource is found, the path of the resolved resource is compared to ensure it's under the input location where it was found. However sometimes that may not be the case, e.g. when `CssLinkResourceTransformer` resolves public URLs of links it contains, the CSS file is the location and the resources being resolved are css files, images, fonts and others located in adjacent or parent directories.

      This property allows configuring a complete list of locations under which resources must be so that if a resource is not under the location relative to which it was found, this list may be checked as well.

      By default `ResourceWebHandler` initializes this property to match its list of locations.

      Parameters:
        `locations` - the list of allowed locations

    - #### getAllowedLocations

          @Nullable
          public Resource[] getAllowedLocations()

    - #### resolveResourceInternal

          protected reactor.core.publisher.Mono<Resource> resolveResourceInternal(@Nullable
                                                                                  ServerWebExchange exchange,
                                                                                  String requestPath,
                                                                                  List<? extends Resource> locations,
                                                                                  ResourceResolverChain chain)

      Specified by:
        `resolveResourceInternal` in class `AbstractResourceResolver`

    - #### resolveUrlPathInternal

          protected reactor.core.publisher.Mono<String> resolveUrlPathInternal(String path,
                                                                               List<? extends Resource> locations,
                                                                               ResourceResolverChain chain)

      Specified by:
        `resolveUrlPathInternal` in class `AbstractResourceResolver`

    - #### getResource

          protected reactor.core.publisher.Mono<Resource> getResource(String resourcePath,
                                                                      Resource location)

      Find the resource under the given location.

      The default implementation checks if there is a readable `Resource` for the given path relative to the location.

      Parameters:
        `resourcePath` - the path to the resource
        `location` - the location to check
      Returns:
        the resource, or empty `Mono` if none found

    - #### checkResource

          protected boolean checkResource(Resource resource,
                                          Resource location)
                                   throws IOException

      Perform additional checks on a resolved resource beyond checking whether the resource exists and is readable. The default implementation also verifies the resource is either under the location relative to which it was found or is under one of the `allowed locations`.
      Parameters:
        `resource` - the resource to check
        `location` - the location relative to which the resource was found
      Returns:
        "true" if resource is in a valid location, "false" otherwise.
      Throws:
        `IOException`