Class HttpURI

java.lang.Object
org.eclipse.jetty.http.HttpURI

public class HttpURI extends 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 Details

    • __ambiguousSegments

      private static final Trie<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 String _scheme
    • _user

      private String _user
    • _host

      private String _host
    • _port

      private int _port
    • _path

      private String _path
    • _param

      private String _param
    • _query

      private String _query
    • _fragment

      private String _fragment
    • _uri

      private String _uri
    • _decodedPath

      private String _decodedPath
    • _ambiguous

      private final EnumSet<HttpURI.Ambiguous> _ambiguous
  • Constructor Details

  • Method Details

    • createHttpURI

      public static HttpURI createHttpURI(String scheme, String host, int port, String path, String param, String query, 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(String uri)
    • parseRequestTarget

      public void parseRequestTarget(String method, 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(String uri)
      Deprecated.
    • parse

      public void parse(String uri, int offset, int length)
    • parse

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

      private void checkSegment(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 '..;'
    • isAmbiguous

      public boolean isAmbiguous()
      Returns:
      True if the URI has either an hasAmbiguousSegment() or hasAmbiguousSeparator().
    • getScheme

      public String getScheme()
    • getHost

      public String getHost()
    • getPort

      public int getPort()
    • getPath

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

      public String getDecodedPath()
      Returns:
      The decoded canonical path.
      See Also:
    • getParam

      public String getParam()
    • setParam

      public void setParam(String param)
    • getQuery

      public String getQuery()
    • hasQuery

      public boolean hasQuery()
    • getFragment

      public String getFragment()
    • decodeQueryTo

      public void decodeQueryTo(MultiMap<String> parameters)
    • decodeQueryTo

      public void decodeQueryTo(MultiMap<String> parameters, String encoding) throws UnsupportedEncodingException
      Throws:
      UnsupportedEncodingException
    • decodeQueryTo

      public void decodeQueryTo(MultiMap<String> parameters, Charset encoding) throws UnsupportedEncodingException
      Throws:
      UnsupportedEncodingException
    • isAbsolute

      public boolean isAbsolute()
    • toString

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

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

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

      public void setScheme(String scheme)
    • setAuthority

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

      public void setPath(String path)
      Parameters:
      path - the path
    • setPathQuery

      public void setPathQuery(String pathQuery)
    • setQuery

      public void setQuery(String query)
    • toURI

      public URI toURI() throws URISyntaxException
      Throws:
      URISyntaxException
    • getPathQuery

      public String getPathQuery()
    • getAuthority

      public String getAuthority()
    • getUser

      public String getUser()