Class ResourceHandlerUtils

java.lang.Object
org.springframework.web.reactive.resource.ResourceHandlerUtils

public abstract class ResourceHandlerUtils extends Object
Resource handling utility methods to share common logic between ResourceWebHandler and org.springframework.web.reactive.function.server.
Since:
6.2
Author:
Rossen Stoyanchev
  • Constructor Details

    • ResourceHandlerUtils

      public ResourceHandlerUtils()
  • Method Details

    • normalizeInputPath

      public static String normalizeInputPath(String path)
      Normalize the given resource path replacing the following:
      • Backslash with forward slash.
      • Duplicate occurrences of slash with a single slash.
      • Any combination of leading slash and control characters (00-1F and 7F) with a single "/" or "". For example " / // foo/bar" becomes "/foo/bar".
    • shouldIgnoreInputPath

      public static boolean shouldIgnoreInputPath(String path)
      Whether the given input path is invalid as determined by isInvalidPath(String). The path is also decoded and the same checks are performed again.
    • isInvalidPath

      public static boolean isInvalidPath(String path)
      Checks for invalid resource input paths rejecting the following:

      Note: this method assumes that leading, duplicate '/' or control characters (e.g. white space) have been trimmed so that the path starts predictably with a single '/' or does not have one.

      Parameters:
      path - the path to validate
      Returns:
      true if the path is invalid, false otherwise
    • createRelativeResource

      public static Resource createRelativeResource(Resource location, String resourcePath) throws IOException
      Create a resource relative to the given Resource, also decoding the resource path for a UrlResource.
      Throws:
      IOException
    • isResourceUnderLocation

      public static boolean isResourceUnderLocation(Resource location, Resource resource) throws IOException
      Check whether the resource is under the given location.
      Throws:
      IOException