Package org.htmlunit.http
Class HttpUtils
- java.lang.Object
-
- org.htmlunit.http.HttpUtils
-
public final class HttpUtils extends java.lang.Object
Http related utils.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
HttpUtils.ParseRange
-
Field Summary
Fields Modifier and Type Field Description private static java.time.format.DateTimeFormatter
FORMATTER_ASCTIME
ASCII time date formatter.private static java.time.format.DateTimeFormatter
FORMATTER_RFC1036
RFC 1036 date formatter.private static java.time.format.DateTimeFormatter
FORMATTER_RFC1123
RFC 1123 date formatter.private static java.time.ZoneId
GMT_ID
private static java.lang.String
PATTERN_ASCTIME
Date format pattern used to parse HTTP date headers in ANSI Casctime()
format.static java.lang.String
PATTERN_RFC1036
Date format pattern used to parse HTTP date headers in RFC 1036 format.private static java.lang.String
PATTERN_RFC1123
Date format pattern used to parse HTTP date headers in RFC 1123 format.private static java.time.format.DateTimeFormatter[]
STANDARD_PATTERNS
private static java.util.BitSet
URLENCODER
Safe characters for x-www-form-urlencoded data; i.e.
-
Constructor Summary
Constructors Modifier Constructor Description private
HttpUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static void
copyContent(java.lang.String buf, HttpUtils.ParseRange range, java.util.BitSet delimiters, java.lang.StringBuilder dst)
Transfers content into the destination buffer until a whitespace character or any of the given delimiters is encountered.private static java.lang.String
decodeFormFields(java.lang.String content, java.nio.charset.Charset charset)
private static java.lang.String
encodeFormFields(java.lang.String content, java.nio.charset.Charset charset)
static java.lang.String
formatDate(java.util.Date date)
Formats the given date according to the RFC 1123 pattern.private static boolean
isWhitespace(char ch)
static java.util.Date
parseDate(java.lang.String dateValue)
Parses a date value.private static java.lang.String
parseToken(java.lang.String buf, HttpUtils.ParseRange range, java.util.BitSet delimiters)
Extracts from the sequence of chars a token terminated with any of the given delimiters discarding semantically insignificant whitespace characters.static java.util.List<NameValuePair>
parseUrlQuery(java.lang.String s, java.nio.charset.Charset charset)
Returns a list ofNameValuePair
s URI query parameters.private static void
skipWhiteSpace(java.lang.String buf, HttpUtils.ParseRange range)
Skips semantically insignificant whitespace characters and moves the cursor to the closest non-whitespace character.static java.lang.String
toQueryFormFields(java.lang.Iterable<? extends NameValuePair> parameters, java.nio.charset.Charset charset)
-
-
-
Field Detail
-
URLENCODER
private static final java.util.BitSet URLENCODER
Safe characters for x-www-form-urlencoded data; i.e. alphanumeric plus"-", "_", ".", "*"
-
PATTERN_RFC1123
private static final java.lang.String PATTERN_RFC1123
Date format pattern used to parse HTTP date headers in RFC 1123 format.- See Also:
- Constant Field Values
-
FORMATTER_RFC1123
private static final java.time.format.DateTimeFormatter FORMATTER_RFC1123
RFC 1123 date formatter.
-
PATTERN_RFC1036
public static final java.lang.String PATTERN_RFC1036
Date format pattern used to parse HTTP date headers in RFC 1036 format.- See Also:
- Constant Field Values
-
FORMATTER_RFC1036
private static final java.time.format.DateTimeFormatter FORMATTER_RFC1036
RFC 1036 date formatter.
-
PATTERN_ASCTIME
private static final java.lang.String PATTERN_ASCTIME
Date format pattern used to parse HTTP date headers in ANSI Casctime()
format.- See Also:
- Constant Field Values
-
FORMATTER_ASCTIME
private static final java.time.format.DateTimeFormatter FORMATTER_ASCTIME
ASCII time date formatter.
-
STANDARD_PATTERNS
private static final java.time.format.DateTimeFormatter[] STANDARD_PATTERNS
-
GMT_ID
private static final java.time.ZoneId GMT_ID
-
-
Method Detail
-
parseDate
public static java.util.Date parseDate(java.lang.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 java.lang.String formatDate(java.util.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:
PATTERN_RFC1123
-
parseUrlQuery
public static java.util.List<NameValuePair> parseUrlQuery(java.lang.String s, java.nio.charset.Charset charset)
Returns a list ofNameValuePair
s 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 java.lang.String decodeFormFields(java.lang.String content, java.nio.charset.Charset charset)
-
toQueryFormFields
public static java.lang.String toQueryFormFields(java.lang.Iterable<? extends NameValuePair> parameters, java.nio.charset.Charset charset)
- Parameters:
parameters
- the paramterscharset
- the charset- Returns:
- the query string from the given parameters
-
encodeFormFields
private static java.lang.String encodeFormFields(java.lang.String content, java.nio.charset.Charset charset)
-
parseToken
private static java.lang.String parseToken(java.lang.String buf, HttpUtils.ParseRange range, java.util.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 parsedrange
- defines the bounds and current position of the bufferdelimiters
- set of delimiting characters. Can benull
if the token is not delimited by any character.
-
skipWhiteSpace
private static void skipWhiteSpace(java.lang.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 parsedrange
- defines the bounds and current position of the buffer
-
copyContent
private static void copyContent(java.lang.String buf, HttpUtils.ParseRange range, java.util.BitSet delimiters, java.lang.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 parsedrange
- defines the bounds and current position of the bufferdelimiters
- set of delimiting characters. Can benull
if the value is delimited by a whitespace only.dst
- destination buffer
-
isWhitespace
private static boolean isWhitespace(char ch)
-
-