Class QueryStringDecoder

java.lang.Object
io.micronaut.http.uri.QueryStringDecoder

@Internal public final class QueryStringDecoder extends Object
Splits an HTTP query string into a path string and key-value parameter pairs. This decoder is for one time use only. Create a new instance for each URI:
 
 QueryStringDecoder decoder = new QueryStringDecoder("/hello?recipient=world&x=1;y=2");
 assert decoder.path().equals("/hello");
 assert decoder.parameters().get("recipient").get(0).equals("world");
 assert decoder.parameters().get("x").get(0).equals("1");
 assert decoder.parameters().get("y").get(0).equals("2");
 
 
This decoder can also decode the content of an HTTP POST request whose content type is application/x-www-form-urlencoded:
 
 QueryStringDecoder decoder = new QueryStringDecoder("recipient=world&x=1;y=2", false);
 ...
 
 
HashDOS vulnerability fix As a workaround to the HashDOS vulnerability, the decoder limits the maximum number of decoded key-value parameter pairs, up to 1024 by default, and you can configure it when you construct the decoder by passing an additional integer parameter. Note: Forked from Netty core. This class is used internally by other Micronaut Modules. Don't reduce visibility.
  • Constructor Details

    • QueryStringDecoder

      public QueryStringDecoder(String uri)
      Creates a new decoder that decodes the specified URI. The decoder will assume that the query string is encoded in UTF-8.
      Parameters:
      uri - The URI
    • QueryStringDecoder

      public QueryStringDecoder(String uri, boolean hasPath)
      Creates a new decoder that decodes the specified URI encoded in the specified charset.
      Parameters:
      uri - The URI
      hasPath - whether a path is present
    • QueryStringDecoder

      public QueryStringDecoder(String uri, Charset charset)
      Creates a new decoder that decodes the specified URI encoded in the specified charset.
      Parameters:
      uri - The URI
      charset - The charset to use
    • QueryStringDecoder

      public QueryStringDecoder(String uri, Charset charset, boolean hasPath)
      Creates a new decoder that decodes the specified URI encoded in the specified charset.
      Parameters:
      uri - The URI
      charset - The charset to use
      hasPath - whether a path is present
    • QueryStringDecoder

      public QueryStringDecoder(String uri, Charset charset, boolean hasPath, int maxParams)
      Creates a new decoder that decodes the specified URI encoded in the specified charset.
      Parameters:
      uri - The URI
      charset - The charset to use
      hasPath - whether a path is present
      maxParams - The maximum number of params
    • QueryStringDecoder

      public QueryStringDecoder(String uri, Charset charset, boolean hasPath, int maxParams, boolean semicolonIsNormalChar)
    • QueryStringDecoder

      public QueryStringDecoder(URI uri)
      Creates a new decoder that decodes the specified URI. The decoder will assume that the query string is encoded in UTF-8.
      Parameters:
      uri - The URI
    • QueryStringDecoder

      public QueryStringDecoder(URI uri, Charset charset)
      Creates a new decoder that decodes the specified URI encoded in the specified charset.
      Parameters:
      uri - The URI
      charset - The charset to use
    • QueryStringDecoder

      public QueryStringDecoder(URI uri, Charset charset, int maxParams)
      Creates a new decoder that decodes the specified URI encoded in the specified charset.
      Parameters:
      uri - The URI
      charset - The charset to use
      maxParams - The maximum number of params
    • QueryStringDecoder

      public QueryStringDecoder(URI uri, Charset charset, int maxParams, boolean semicolonIsNormalChar)
  • Method Details

    • toString

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

      public String uri()
      Returns:
      Returns the uri used to initialize this QueryStringDecoder.
    • path

      public String path()
      Returns:
      Returns the decoded path string of the URI.
    • parameters

      public Map<String,List<String>> parameters()
      Returns:
      Returns the decoded key-value parameter pairs of the URI.
    • rawPath

      public String rawPath()
      Returns:
      Returns the raw path string of the URI.
    • rawQuery

      public String rawQuery()
      Returns:
      Returns raw query string of the URI.
    • decodeComponent

      public static String decodeComponent(String s)
      Decodes a bit of a URL encoded by a browser.

      This is equivalent to calling decodeComponent(String, Charset) with the UTF-8 charset (recommended to comply with RFC 3986, Section 2).

      Parameters:
      s - The string to decode (can be empty).
      Returns:
      The decoded string, or s if there's nothing to decode. If the string to decode is null, returns an empty string.
      Throws:
      IllegalArgumentException - if the string contains a malformed escape sequence.