-
- All Known Implementing Classes:
HttpURI.Immutable,HttpURI.Mutable
public interface HttpURIHttp URI. BothHttpURI.MutableandHttpURI.Immutableimplementations are available via the static methods such asbuild()andfrom(String). A URI such ashttp://user@host:port/path;param1/%2e/info;param2?query#fragmentis split into the following optional elements:getScheme()- http:getAuthority()- //name@host:portgetHost()- hostgetPort()- portgetPath()- /path;param1/%2e/info;param2getDecodedPath()- /path/infogetParam()- param2getQuery()- querygetFragment()- fragment
The path part of the URI is provided in both raw form (
getPath()) and decoded form (getDecodedPath()), which has: path parameters removed, percent encoded characters expanded and relative segments resolved. This approach is somewhat contrary to RFC3986 which no longer defines path parameters (removed after RFC2396) and specifies that relative segment normalization should take place before percent encoded character expansion. A literal interpretation of the RFC can result in URI paths with ambiguities when viewed as strings. For example, a URI of/foo%2f..%2fbaris technically a single segment of "/foo/../bar", but could easily be misinterpreted as 3 segments resolving to "/bar" by a file system.Thus this class avoid and/or detects such ambiguities. Furthermore, by decoding characters and removing parameters before relative path normalization, ambiguous paths will be resolved in such a way to be non-standard-but-non-ambiguous to down stream interpretation of the decoded path string. The violations are recorded and available by API such as
hasAmbiguousSegment()so that requests containing them may be rejected in case the non-standard-but-non-ambiguous interpretations are not satisfactory for a given compliance configuration.Implementations that wish to process ambiguous URI paths must configure the compliance modes to accept them and then perform their own decoding of
getPath().If there are multiple path parameters, only the last one is returned by
getParam().
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classHttpURI.Immutablestatic classHttpURI.Mutable
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description HttpURI.ImmutableasImmutable()java.lang.StringasString()static HttpURI.Mutablebuild()static HttpURI.Mutablebuild(java.lang.String uri)static HttpURI.Mutablebuild(java.net.URI uri)static HttpURI.Mutablebuild(HttpURI uri)static HttpURI.Mutablebuild(HttpURI uri, java.lang.String pathQuery)static HttpURI.Mutablebuild(HttpURI uri, java.lang.String path, java.lang.String param, java.lang.String query)static HttpURI.Immutablefrom(java.lang.String uri)static HttpURI.Immutablefrom(java.lang.String method, java.lang.String uri)static HttpURI.Immutablefrom(java.lang.String scheme, java.lang.String host, int port, java.lang.String pathQuery)static HttpURI.Immutablefrom(java.net.URI uri)java.lang.StringgetAuthority()java.lang.StringgetDecodedPath()java.lang.StringgetFragment()java.lang.StringgetHost()java.lang.StringgetParam()Get a URI path parameter.java.lang.StringgetPath()java.lang.StringgetPathQuery()intgetPort()java.lang.StringgetQuery()java.lang.StringgetScheme()java.lang.StringgetUser()java.util.Collection<UriCompliance.Violation>getViolations()default booleanhasAmbiguousEmptySegment()default booleanhasAmbiguousEncoding()default booleanhasAmbiguousParameter()default booleanhasAmbiguousSegment()default booleanhasAmbiguousSeparator()booleanhasAuthority()default booleanhasUtf16Encoding()booleanhasViolation(UriCompliance.Violation violation)booleanhasViolations()booleanisAbsolute()booleanisAmbiguous()default java.net.URItoURI()
-
-
-
Method Detail
-
build
static HttpURI.Mutable build()
-
build
static HttpURI.Mutable build(HttpURI uri)
-
build
static HttpURI.Mutable build(HttpURI uri, java.lang.String pathQuery)
-
build
static HttpURI.Mutable build(HttpURI uri, java.lang.String path, java.lang.String param, java.lang.String query)
-
build
static HttpURI.Mutable build(java.net.URI uri)
-
build
static HttpURI.Mutable build(java.lang.String uri)
-
from
static HttpURI.Immutable from(java.net.URI uri)
-
from
static HttpURI.Immutable from(java.lang.String uri)
-
from
static HttpURI.Immutable from(java.lang.String method, java.lang.String uri)
-
from
static HttpURI.Immutable from(java.lang.String scheme, java.lang.String host, int port, java.lang.String pathQuery)
-
asImmutable
HttpURI.Immutable asImmutable()
-
asString
java.lang.String asString()
-
getAuthority
java.lang.String getAuthority()
-
getDecodedPath
java.lang.String getDecodedPath()
-
getFragment
java.lang.String getFragment()
-
getHost
java.lang.String getHost()
-
getParam
java.lang.String getParam()
Get a URI path parameter. Multiple and in segment parameters are ignored and only the last trailing parameter is returned.- Returns:
- The last path parameter or null
-
getPath
java.lang.String getPath()
-
getPathQuery
java.lang.String getPathQuery()
-
getPort
int getPort()
-
getQuery
java.lang.String getQuery()
-
getScheme
java.lang.String getScheme()
-
getUser
java.lang.String getUser()
-
hasAuthority
boolean hasAuthority()
-
isAbsolute
boolean isAbsolute()
-
isAmbiguous
boolean isAmbiguous()
- Returns:
- True if the URI has any ambiguous
UriCompliance.Violations.
-
hasViolations
boolean hasViolations()
- Returns:
- True if the URI has any
UriCompliance.Violations.
-
hasViolation
boolean hasViolation(UriCompliance.Violation violation)
- Parameters:
violation- the violation to check.- Returns:
- true if the URI has the passed violation.
-
getViolations
java.util.Collection<UriCompliance.Violation> getViolations()
- Returns:
- Set of violations in the URI.
-
hasAmbiguousSegment
default boolean hasAmbiguousSegment()
- Returns:
- True if the URI has a possibly ambiguous segment like '..;' or '%2e%2e'
-
hasAmbiguousEmptySegment
default boolean hasAmbiguousEmptySegment()
- Returns:
- True if the URI empty segment that is ambiguous like '//' or '/;param/'.
-
hasAmbiguousSeparator
default boolean hasAmbiguousSeparator()
- Returns:
- True if the URI has a possibly ambiguous separator of %2f
-
hasAmbiguousParameter
default boolean hasAmbiguousParameter()
- Returns:
- True if the URI has a possibly ambiguous path parameter like '..;'
-
hasAmbiguousEncoding
default boolean hasAmbiguousEncoding()
- Returns:
- True if the URI has an encoded '%' character.
-
hasUtf16Encoding
default boolean hasUtf16Encoding()
- Returns:
- True if the URI has UTF16 '%u' encodings.
-
toURI
default java.net.URI toURI()
-
-