Class UriUtil

java.lang.Object
io.micronaut.web.router.uri.UriUtil

public final class UriUtil extends Object
Utilities for converting URI formats.
Since:
4.9.0
Author:
Jonas Konrad
  • Method Details

    • toValidPath

      public static String toValidPath(String path)
      Transform a path+query as specified by the whatwg url spec into a path+query that is allowed by RFC 3986. Whatwg permits certain characters (e.g. '|') and invalid percent escape sequences that RFC 3986 (or URI) does not allow. This method will percent-encode those cases, so that any URI sent by a browser can be transformed to URI.
      Parameters:
      path - The whatwg path+query
      Returns:
      A valid RFC 3986 relative-ref
    • isValidPath

      public static boolean isValidPath(@NonNull @NonNull String requestTarget)
      Check whether the given HTTP request target is a valid RFC 3986 relative URI (path + query) that will be parsed without complaint by URI. If this is true, we can skip the expensive parsing until necessary.
      Parameters:
      requestTarget - The HTTP request line
      Returns:
      true iff this is a valid relative URI
    • isRelative

      public static boolean isRelative(@NonNull @NonNull String requestTarget)
      Determine whether the given HTTP request target is a relative URI (path+query) appropriate for toValidPath(String). The invariants are:
      • This method returns true exactly when, according to the whatwg URL spec, this URL has no scheme
      • If the input is a valid URI, this method is equal to the inverse of URI.isAbsolute()
      • If this method returns true, and the input is a valid URI after going through toValidPath(String), URI.isAbsolute() is false
      Parameters:
      requestTarget - The HTTP request target
      Returns:
      true if this URL is relative