Class HttpUtils

java.lang.Object
org.htmlunit.http.HttpUtils

public final class HttpUtils extends Object
Http related utils.
  • Field Details

    • URLENCODER

      private static final BitSet URLENCODER
      Safe characters for x-www-form-urlencoded data; i.e. alphanumeric plus "-", "_", ".", "*"
    • PATTERN_RFC1123

      private static final String PATTERN_RFC1123
      Date format pattern used to parse HTTP date headers in RFC 1123 format.
      See Also:
    • FORMATTER_RFC1123

      private static final DateTimeFormatter FORMATTER_RFC1123
      RFC 1123 date formatter.
    • PATTERN_RFC1036

      public static final String PATTERN_RFC1036
      Date format pattern used to parse HTTP date headers in RFC 1036 format.
      See Also:
    • FORMATTER_RFC1036

      private static final DateTimeFormatter FORMATTER_RFC1036
      RFC 1036 date formatter.
    • PATTERN_ASCTIME

      private static final String PATTERN_ASCTIME
      Date format pattern used to parse HTTP date headers in ANSI C asctime() format.
      See Also:
    • FORMATTER_ASCTIME

      private static final DateTimeFormatter FORMATTER_ASCTIME
      ASCII time date formatter.
    • STANDARD_PATTERNS

      private static final DateTimeFormatter[] STANDARD_PATTERNS
    • GMT_ID

      private static final ZoneId GMT_ID
  • Constructor Details

    • HttpUtils

      private HttpUtils()
  • Method Details

    • parseDate

      public static Date parseDate(String dateValue)
      Parses a date value. The formats used for parsing the date value are retrieved from the default http params.
      Parameters:
      dateValue - the date value to parse
      Returns:
      the parsed date or null if input could not be parsed
    • formatDate

      public static String formatDate(Date date)
      Formats the given date according to the RFC 1123 pattern.
      Parameters:
      date - The date to format.
      Returns:
      An RFC 1123 formatted date string.
      See Also:
    • parseUrlQuery

      public static List<NameValuePair> parseUrlQuery(String s, Charset charset)
      Returns a list of NameValuePairs URI query parameters. By convention, '&' and ';' are accepted as parameter separators.
      Parameters:
      s - URI query component.
      charset - charset to use when decoding the parameters.
      Returns:
      list of query parameters.
    • decodeFormFields

      private static String decodeFormFields(String content, Charset charset)
    • toQueryFormFields

      public static String toQueryFormFields(Iterable<? extends NameValuePair> parameters, Charset charset)
      Parameters:
      parameters - the paramters
      charset - the charset
      Returns:
      the query string from the given parameters
    • encodeFormFields

      private static String encodeFormFields(String content, Charset charset)
    • parseToken

      private static String parseToken(String buf, HttpUtils.ParseRange range, BitSet delimiters)
      Extracts from the sequence of chars a token terminated with any of the given delimiters discarding semantically insignificant whitespace characters.
      Parameters:
      buf - buffer with the sequence of chars to be parsed
      range - defines the bounds and current position of the buffer
      delimiters - set of delimiting characters. Can be null if the token is not delimited by any character.
    • skipWhiteSpace

      private static void skipWhiteSpace(String buf, HttpUtils.ParseRange range)
      Skips semantically insignificant whitespace characters and moves the cursor to the closest non-whitespace character.
      Parameters:
      buf - buffer with the sequence of chars to be parsed
      range - defines the bounds and current position of the buffer
    • copyContent

      private static void copyContent(String buf, HttpUtils.ParseRange range, BitSet delimiters, StringBuilder dst)
      Transfers content into the destination buffer until a whitespace character or any of the given delimiters is encountered.
      Parameters:
      buf - buffer with the sequence of chars to be parsed
      range - defines the bounds and current position of the buffer
      delimiters - set of delimiting characters. Can be null if the value is delimited by a whitespace only.
      dst - destination buffer
    • isWhitespace

      private static boolean isWhitespace(char ch)