Class HeaderUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatDate(Date date) Formats aHTTP-dateusing RFC 1123 format as specified in RFC 2616.static Stringjoin(Collection<String> values, char separator) Joins a collection of header values into a single header value, with a specified specified separator.static DateParses the supportedHTTP-dateformats as specified in RFC 2616.static DirectiveparseDirective(String value) Splits a single HTTP directive name and value from an input string value.parseDirectives(Collection<String> values) Parses a set of HTTP directives from a collection of values.Parses a set of HTTP directives from a collection of values.parseMultiValuedHeader(String header) Parses the header content as a multi-valued comma separated value.parseMultiValuedHeader(Message<?> message, String name) Parses the named header from the message as a multi-valued comma separated value.static StringparseSingleValuedHeader(Message<?> message, String name) Parses the named single-valued header from the message.static StringEncloses a string in quotation marks.Parses an HTTP header value, splitting it into multiple values around the specified separator.static StringUnquotes a string following the logic ofquote(String).
-
Method Details
-
split
Parses an HTTP header value, splitting it into multiple values around the specified separator. Quoted strings are not split into multiple values if they contain separator characters. All leading and trailing white space in values is trimmed. All quotations remain intact.Note: This method is liberal in its interpretation of malformed header values; namely the incorrect use of string and character quoting mechanisms and unquoted white space. If a
nullor empty string is supplied as a value, this method yields an empty list.- Parameters:
value- the header value to be split.separator- the separator character to split headers around.- Returns:
- A list of string representing the split values of the header.
-
join
Joins a collection of header values into a single header value, with a specified specified separator. Anullor empty collection of header values yeilds anullreturn value.- Parameters:
values- the values to be joined.separator- the separator to separate values within the returned value.- Returns:
- a single header value, with values separated by the separator.
-
parseDirective
Splits a single HTTP directive name and value from an input string value. The input string value is presumed to have been extracted from a collection provided by thesplit(String, char)method.This method returns the directive name-value pair as a
Directive.A value that is contained within a quoted-string is processed such that the surrounding '"' (quotation mark) characters are removed and single-character quotations hold the character being quoted without the escape '\' (backslash) character. White space is discarded unless it is within the quoted-string or a directive value.
Note: This method is liberal in its interpretation of a malformed directive value; namely the incorrect use of string and character quoting mechanisms and unquoted white space.
- Parameters:
value- the string to parse the name-value directive from.- Returns:
- the name-value pair as a
Directive.
-
parseDirectives
Parses a set of HTTP directives from a collection of values. The input collection of values is presumed to have been provided from thesplit(String, char)method.A well-formed directives contains an attribute and optional value, separated by an '=' (equals sign) character. If the directives contains no value, it is represented by a
nullvalue in the returned map.Values that are contained in quoted-strings are processed such that the surrounding '"' (quotation mark) characters are removed and single-character quotations hold the character being quoted without the escape '\' (backslash) character. White space is discarded unless it is within the quoted-string or a directive value.
Note: This method is liberal in its interpretation of malformed directive values; namely the incorrect use of string and character quoting mechanisms and unquoted white space.
- Parameters:
values- the HTTP directives.- Returns:
- a map of directive name-value pairs or an empty map if values was null.
-
parseDirectivesAsDirectiveMap
Parses a set of HTTP directives from a collection of values. The input collection of values is presumed to have been provided from thesplit(String, char)method.- Parameters:
values- the HTTP directives.- Returns:
- a map of $
Directiveobjects based on all the unique directives found or an empty map if values was null.
-
quote
Encloses a string in quotation marks. Quotation marks and backslash characters are escaped with the single-character quoting mechanism. For more information, see RFC 2616 ยง2.2.- Parameters:
value- the value to be enclosed in quotation marks.- Returns:
- the value enclosed in quotation marks.
-
unquote
Unquotes a string following the logic ofquote(String).- Parameters:
value- Value to unquote- Returns:
- Unquoted value
-
parseMultiValuedHeader
Parses the named header from the message as a multi-valued comma separated value. If there are multiple headers present then they are first merged and thensplit.- Parameters:
message- The HTTP request or response.name- The name of the header.- Returns:
- A list of strings representing the split values of the header, which may be empty if the header was not present in the message.
-
parseMultiValuedHeader
Parses the header content as a multi-valued comma separated value.- Parameters:
header- The HTTP header content.- Returns:
- A list of strings representing the split values of the header,
which may be empty if the header was
nullor empty.
-
parseSingleValuedHeader
Parses the named single-valued header from the message. If there are multiple headers present then only the first is used.- Parameters:
message- The HTTP request or response.name- The name of the header.- Returns:
- The header value, or
nullif the header was not present in the message.
-
formatDate
Formats aHTTP-dateusing RFC 1123 format as specified in RFC 2616.- Parameters:
date-Dateto format- Returns:
- Formatted
HTTP-date
-
parseDate
Parses the supportedHTTP-dateformats as specified in RFC 2616.
-