Class Cookies
Cookie header (RFC 6265bis section
4.2).
Accepted: name=value pairs separated by exactly "; ". A name is a non-empty
HTTP token; a value consists of cookie octets only (visible ASCII without space, double quote,
comma, semicolon or backslash) and may be empty. Anything else (quoted values, stray whitespace,
a pair without =, a nameless cookie, control or non-ASCII characters, more than 128 pairs, a header longer than the limit) makes the whole header invalid: parse(java.lang.String)
throws, and of(Request) answers "no cookies", so security decisions fail closed instead
of reading a half-understood header.
A name that appears twice is ambiguous (a sibling sub-domain can plant a second cookie of the
same name), so get(java.lang.String) treats it as absent; all(java.lang.String) shows every value.
Immutable and thread-safe. Values are credentials when they are session identifiers or tokens:
toString() lists only the names.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault longestCookieheader accepted, in characters.static final intMost cookie pairs accepted in one header. -
Method Summary
Modifier and TypeMethodDescriptionReturns every value sent for the name, in header order.Returns the value of the cookie, if it was sent exactly once.names()Returns the distinct cookie names.static Cookiesnone()Returns no cookies.static CookiesReads the request's cookies; a missing, oversized or malformed header yields none.static CookiesReads the request's cookies with a header size limit; a missing, oversized or malformed header yields none.static CookiesParses aCookieheader value strictly with the default size limit.static CookiesParses aCookieheader value strictly.toString()
-
Field Details
-
DEFAULT_MAX_LENGTH
public static final int DEFAULT_MAX_LENGTHDefault longestCookieheader accepted, in characters.- See Also:
-
MAX_PAIRS
public static final int MAX_PAIRSMost cookie pairs accepted in one header.- See Also:
-
-
Method Details
-
none
Returns no cookies.- Returns:
- an empty set
-
of
Reads the request's cookies; a missing, oversized or malformed header yields none.- Parameters:
request- the request- Returns:
- the cookies, empty when the header is absent or invalid
-
of
Reads the request's cookies with a header size limit; a missing, oversized or malformed header yields none.- Parameters:
request- the requestmaxLength- longest accepted header, 64 to 65,536 characters- Returns:
- the cookies, empty when the header is absent or invalid
-
parse
Parses aCookieheader value strictly with the default size limit.- Parameters:
header- the header value- Returns:
- the cookies
- Throws:
IllegalArgumentException- if the header is malformed or too long
-
parse
Parses aCookieheader value strictly.- Parameters:
header- the header valuemaxLength- longest accepted header, 64 to 65,536 characters- Returns:
- the cookies
- Throws:
IllegalArgumentException- if the header is malformed or longer thanmaxLength
-
get
Returns the value of the cookie, if it was sent exactly once.- Parameters:
name- cookie name, case-sensitive- Returns:
- the value, or empty when absent or sent more than once
-
all
Returns every value sent for the name, in header order.- Parameters:
name- cookie name, case-sensitive- Returns:
- the values, possibly none
-
names
Returns the distinct cookie names.- Returns:
- the names in header order
-
toString
-