Class HttpURI


  • public class HttpURI
    extends java.lang.Object
    Http URI. Parse an HTTP URI from a string or byte array. Given a URI http://user@host:port/path/info;param?query#fragment this class will split it into the following undecoded optional elements:

    Any parameters will be returned from getPath(), but are excluded from the return value of getDecodedPath(). If there are multiple parameters, the getParam() method returns only the last one.

    • Field Detail

      • __ambiguousSegments

        private static final Trie<java.lang.Boolean> __ambiguousSegments
        The concept of URI path parameters was originally specified in RFC2396, but that was obsoleted by RFC3986 which removed a normative definition of path parameters. Specifically it excluded them from the Remove Dot Segments algorithm. This results in some ambiguity as dot segments can result from later parameter removal or % encoding expansion, that are not removed from the URI by URIUtil.canonicalPath(String). Thus this class flags such ambiguous path segments, so that they may be rejected by the server if so configured.
      • _scheme

        private java.lang.String _scheme
      • _user

        private java.lang.String _user
      • _host

        private java.lang.String _host
      • _port

        private int _port
      • _path

        private java.lang.String _path
      • _param

        private java.lang.String _param
      • _query

        private java.lang.String _query
      • _fragment

        private java.lang.String _fragment
      • _uri

        private java.lang.String _uri
      • _decodedPath

        private java.lang.String _decodedPath
    • Constructor Detail

      • HttpURI

        public HttpURI()
      • HttpURI

        public HttpURI​(java.lang.String scheme,
                       java.lang.String host,
                       int port,
                       java.lang.String path,
                       java.lang.String param,
                       java.lang.String query,
                       java.lang.String fragment)
      • HttpURI

        public HttpURI​(HttpURI uri)
      • HttpURI

        public HttpURI​(java.lang.String uri)
      • HttpURI

        public HttpURI​(java.net.URI uri)
      • HttpURI

        public HttpURI​(java.lang.String scheme,
                       java.lang.String host,
                       int port,
                       java.lang.String pathQuery)
    • Method Detail

      • createHttpURI

        public static HttpURI createHttpURI​(java.lang.String scheme,
                                            java.lang.String host,
                                            int port,
                                            java.lang.String path,
                                            java.lang.String param,
                                            java.lang.String query,
                                            java.lang.String fragment)
        Construct a normalized URI. Port is not set if it is the default port.
        Parameters:
        scheme - the URI scheme
        host - the URI hose
        port - the URI port
        path - the URI path
        param - the URI param
        query - the URI query
        fragment - the URI fragment
        Returns:
        the normalized URI
      • clear

        public void clear()
      • parse

        public void parse​(java.lang.String uri)
      • parseRequestTarget

        public void parseRequestTarget​(java.lang.String method,
                                       java.lang.String uri)
        Parse according to https://tools.ietf.org/html/rfc7230#section-5.3
        Parameters:
        method - the request method
        uri - the request uri
      • parseConnect

        @Deprecated
        public void parseConnect​(java.lang.String uri)
        Deprecated.
      • parse

        public void parse​(java.lang.String uri,
                          int offset,
                          int length)
      • parse

        private void parse​(HttpURI.State state,
                           java.lang.String uri,
                           int offset,
                           int end)
      • checkSegment

        private void checkSegment​(java.lang.String uri,
                                  int segment,
                                  int end,
                                  boolean param)
        Check for ambiguous path segments. An ambiguous path segment is one that is perhaps technically legal, but is considered undesirable to handle due to possible ambiguity. Examples include segments like '..;', '%2e', '%2e%2e' etc.
        Parameters:
        uri - The URI string
        segment - The inclusive starting index of the segment (excluding any '/')
        end - The exclusive end index of the segment
      • hasAmbiguousSegment

        public boolean hasAmbiguousSegment()
        Returns:
        True if the URI has a possibly ambiguous segment like '..;' or '%2e%2e'
      • hasAmbiguousSeparator

        public boolean hasAmbiguousSeparator()
        Returns:
        True if the URI has a possibly ambiguous separator of %2f
      • hasAmbiguousParameter

        public boolean hasAmbiguousParameter()
        Returns:
        True if the URI has a possibly ambiguous path parameter like '..;'
      • getScheme

        public java.lang.String getScheme()
      • getHost

        public java.lang.String getHost()
      • getPort

        public int getPort()
      • getPath

        public java.lang.String getPath()
        The parsed Path.
        Returns:
        the path as parsed on valid URI. null for invalid URI.
      • getParam

        public java.lang.String getParam()
      • setParam

        public void setParam​(java.lang.String param)
      • getQuery

        public java.lang.String getQuery()
      • hasQuery

        public boolean hasQuery()
      • getFragment

        public java.lang.String getFragment()
      • decodeQueryTo

        public void decodeQueryTo​(MultiMap<java.lang.String> parameters)
      • decodeQueryTo

        public void decodeQueryTo​(MultiMap<java.lang.String> parameters,
                                  java.lang.String encoding)
                           throws java.io.UnsupportedEncodingException
        Throws:
        java.io.UnsupportedEncodingException
      • decodeQueryTo

        public void decodeQueryTo​(MultiMap<java.lang.String> parameters,
                                  java.nio.charset.Charset encoding)
                           throws java.io.UnsupportedEncodingException
        Throws:
        java.io.UnsupportedEncodingException
      • isAbsolute

        public boolean isAbsolute()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • setScheme

        public void setScheme​(java.lang.String scheme)
      • setAuthority

        public void setAuthority​(java.lang.String host,
                                 int port)
        Parameters:
        host - the host
        port - the port
      • setPath

        public void setPath​(java.lang.String path)
        Parameters:
        path - the path
      • setPathQuery

        public void setPathQuery​(java.lang.String pathQuery)
      • setQuery

        public void setQuery​(java.lang.String query)
      • toURI

        public java.net.URI toURI()
                           throws java.net.URISyntaxException
        Throws:
        java.net.URISyntaxException
      • getPathQuery

        public java.lang.String getPathQuery()
      • getAuthority

        public java.lang.String getAuthority()
      • getUser

        public java.lang.String getUser()