Package io.micronaut.web.router.uri
Class UriUtil
java.lang.Object
io.micronaut.web.router.uri.UriUtil
Utilities for converting URI formats.
- Since:
- 4.9.0
- Author:
- Jonas Konrad
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
isRelative
(@NonNull String requestTarget) Determine whether the given HTTP request target is a relative URI (path+query) appropriate fortoValidPath(String)
.static boolean
isValidPath
(@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 byURI
.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.
-
Method Details
-
toValidPath
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 (orURI
) does not allow. This method will percent-encode those cases, so that any URI sent by a browser can be transformed toURI
.- Parameters:
path
- The whatwg path+query- Returns:
- A valid RFC 3986
relative-ref
-
isValidPath
Check whether the given HTTP request target is a valid RFC 3986 relative URI (path + query) that will be parsed without complaint byURI
. 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
Determine whether the given HTTP request target is a relative URI (path+query) appropriate fortoValidPath(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 throughtoValidPath(String)
,URI.isAbsolute()
isfalse
- Parameters:
requestTarget
- The HTTP request target- Returns:
true
if this URL is relative
- This method returns
-