public final class HeaderUtil extends Object
Modifier and Type | Method and Description |
---|---|
static String |
formatDate(Date date)
Formats a
HTTP-date using RFC 1123 format as specified in
RFC 2616. |
static String |
join(Collection<String> values,
char separator)
Joins a collection of header values into a single header value, with a
specified specified separator.
|
static Date |
parseDate(String s)
Parses the supported
HTTP-date formats as specified in
RFC 2616. |
static Directive |
parseDirective(String value)
Splits a single HTTP directive name and value from an input string
value.
|
static Map<String,String> |
parseDirectives(Collection<String> values)
Parses a set of HTTP directives from a collection of values.
|
static Map<String,Directive> |
parseDirectivesAsDirectiveMap(Collection<String> values)
Parses a set of HTTP directives from a collection of values.
|
static List<String> |
parseMultiValuedHeader(Message<?> message,
String name)
Parses the named header from the message as a multi-valued comma
separated value.
|
static List<String> |
parseMultiValuedHeader(String header)
Parses the header content as a multi-valued comma separated value.
|
static String |
parseSingleValuedHeader(Message<?> message,
String name)
Parses the named single-valued header from the message.
|
static String |
quote(String value)
Encloses a string in quotation marks.
|
static List<String> |
split(String value,
char separator)
Parses an HTTP header value, splitting it into multiple values around the
specified separator.
|
static String |
unquote(String value)
Unquotes a string following the logic of
HeaderUtil.quote(String) . |
public static List<String> split(String value, char separator)
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 null
or empty string is
supplied as a value, this method yields an empty list.
value
- the header value to be split.separator
- the separator character to split headers around.public static String join(Collection<String> values, char separator)
null
or empty collection of
header values yeilds a null
return value.values
- the values to be joined.separator
- the separator to separate values within the returned value.public static Directive parseDirective(String value)
HeaderUtil.split(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.
value
- the string to parse the name-value directive from.Directive
.public static Map<String,String> parseDirectives(Collection<String> values)
HeaderUtil.split(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 null
value 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.
values
- the HTTP directives.public static Map<String,Directive> parseDirectivesAsDirectiveMap(Collection<String> values)
HeaderUtil.split(String, char)
method.values
- the HTTP directives.Directive
objects based on all the unique directives found or an empty map
if values was null.public static String quote(String value)
value
- the value to be enclosed in quotation marks.public static String unquote(String value)
HeaderUtil.quote(String)
.value
- Value to unquotepublic static List<String> parseMultiValuedHeader(Message<?> message, String name)
split
.message
- The HTTP request or response.name
- The name of the header.public static List<String> parseMultiValuedHeader(String header)
header
- The HTTP header content.null
or empty.public static String parseSingleValuedHeader(Message<?> message, String name)
message
- The HTTP request or response.name
- The name of the header.null
if the header was not present
in the message.public static String formatDate(Date date)
HTTP-date
using RFC 1123 format as specified in
RFC 2616.date
- Date
to formatHTTP-date
Copyright © 2010-2018, ForgeRock All Rights Reserved.