There are 3 HTTP cookie specifications:
Netscape draft
RFC 2109 - http://www.ietf.org/rfc/rfc2109.txt
RFC 2965 - http://www.ietf.org/rfc/rfc2965.txt
HttpCookie class can accept all these 3 forms of syntax.
Modifier and Type | Class and Description |
---|---|
pack-priv static interface |
Modifier and Type | Field and Description |
---|---|
pack-priv static final Map | |
private String | |
private String | |
private static final String[] | |
private String | |
pack-priv static final TimeZone | |
private final String | |
private boolean | |
private static final long | |
private long | |
private final String | |
private String | |
private String | |
private boolean | |
private static final String | |
private static final String | |
private boolean | |
private static final String | |
private String | |
private int | |
private final long |
Access | Constructor and Description |
---|---|
public | HttpCookie(String
a name, String String specifying the name of the cookiea value)String specifying the value of the cookieConstructs a cookie with a specified name and value. |
private | |
pack-priv | HttpCookie(String name, String value, String header, long creationTime)
Package private for testing purposes. |
Modifier and Type | Method and Description |
---|---|
private static void | |
public Object | Returns: a clone of this HTTP cookieOverrides java. Create and return a copy of this object. |
public static boolean | Returns: true if they domain-matches; false if notthe domain name to check host name with domain, String the host name in question host)The utility method to check whether a host name is in a domain or not. |
public boolean | Returns: true if two HTTP cookies equal to each other;
otherwise, false the reference object with which to compare. obj)Overrides java. Test the equality of two HTTP cookies. |
private static boolean | |
private long | |
public String | Returns: aString containing the comment, or null if noneReturns the comment describing the purpose of this cookie, or
|
public String | Returns: aString containing the comment URL, or null
if noneReturns the comment URL describing the purpose of this cookie, or
|
pack-priv long | |
public boolean | Returns: aboolean to represent this cookie's discard attributeReturns the discard attribute of the cookie |
public String | |
public long | Returns: an integer specifying the maximum age of the cookie in secondsReturns the maximum age of the cookie, specified in seconds. |
public String | |
public String | Returns: aString specifying a path that contains a servlet name,
for example, /catalogReturns the path on the server to which the browser returns this cookie. |
public String | Returns: aString contains the port list or null if noneReturns the port list attribute of the cookie |
public boolean | Returns: false if the cookie can be sent over any standard
protocol; otherwise, true Returns |
public String | |
public int | Returns: 0 if the cookie complies with the original Netscape specification; 1 if the cookie complies with RFC 2965/2109Returns the version of the protocol this cookie complies with. |
private static int | |
public boolean | Returns: true to indicate this HTTP cookie has expired;
otherwise, false Reports whether this HTTP cookie has expired or not. |
public int | Returns: this HTTP cookie's hash codeOverrides java. Returns the hash code of this HTTP cookie. |
private String | |
public boolean | Returns: true if this cookie should be considered HTTPOnlyReturns |
private static boolean | |
public static List | |
private static List | |
private static HttpCookie | |
public void | setComment(String
a purpose)String specifying the comment to display to the userSpecifies a comment that describes a cookie's purpose. |
public void | setCommentURL(String
a purpose)String specifying the comment URL to display to the userSpecifies a comment URL that describes a cookie's purpose. |
public void | setDiscard(boolean
true indicates to discard cookie unconditionallySpecify whether user agent should discard the cookie unconditionally. |
public void | |
public void | setHttpOnly(boolean
if httpOnly)true make the cookie HTTP only, i.e. only visible as
part of an HTTP request.Indicates whether the cookie should be considered HTTP Only. |
public void | setMaxAge(long
an integer specifying the maximum age of the cookie in seconds;
if zero, the cookie should be discarded immediately; otherwise,
the cookie's max age is unspecified. expiry)Sets the maximum age of the cookie in seconds. |
public void | |
public void | setPortlist(String
a ports)String specify the port list, which is comma separated
series of digitsSpecify the portlist of the cookie, which restricts the port(s) to which a cookie may be sent back in a Cookie header. |
public void | setSecure(boolean
If flag)true , the cookie can only be sent over a secure
protocol like HTTPS. If false , it can be sent over
any protocol.Indicates whether the cookie should only be sent using a secure protocol, such as HTTPS or SSL. |
public void | |
public void | setVersion(int
0 if the cookie should comply with the original Netscape
specification; 1 if the cookie should comply with RFC 2965/2109 v)Sets the version of the cookie protocol this cookie complies with. |
private static List | |
private static boolean | |
private static String | |
private String | |
private String | |
public String | Returns: a string form of the cookie. The string has the defined formatOverrides java. Constructs a cookie header string representation of this cookie, which is in the format defined by corresponding cookie specification, but without the leading "Cookie:" token. |
assignors | back to summary |
---|---|
pack-priv static final Map<String, HttpCookie. |
comment | back to summary |
---|---|
private String comment |
commentURL | back to summary |
---|---|
private String commentURL |
COOKIE_DATE_FORMATS | back to summary |
---|---|
private static final String[] COOKIE_DATE_FORMATS |
domain | back to summary |
---|---|
private String domain |
GMT | back to summary |
---|---|
pack-priv static final TimeZone GMT |
header | back to summary |
---|---|
private final String header |
httpOnly | back to summary |
---|---|
private boolean httpOnly |
MAX_AGE_UNSPECIFIED | back to summary |
---|---|
private static final long MAX_AGE_UNSPECIFIED |
maxAge | back to summary |
---|---|
private long maxAge |
name | back to summary |
---|---|
private final String name |
path | back to summary |
---|---|
private String path |
portlist | back to summary |
---|---|
private String portlist |
secure | back to summary |
---|---|
private boolean secure |
SET_COOKIE | back to summary |
---|---|
private static final String SET_COOKIE |
SET_COOKIE2 | back to summary |
---|---|
private static final String SET_COOKIE2 |
toDiscard | back to summary |
---|---|
private boolean toDiscard |
tspecials | back to summary |
---|---|
private static final String tspecials |
value | back to summary |
---|---|
private String value |
version | back to summary |
---|---|
private int version |
whenCreated | back to summary |
---|---|
private final long whenCreated |
HttpCookie | back to summary |
---|---|
public HttpCookie(String name, String value) Constructs a cookie with a specified name and value. The name must conform to RFC 2965. That means it can contain only ASCII alphanumeric characters and cannot contain commas, semicolons, or white space or begin with a $ character. The cookie's name cannot be changed after creation. The value can be anything the server chooses to send. Its
value is probably of interest only to the server. The cookie's
value can be changed after creation with the
By default, cookies are created according to the RFC 2965
cookie specification. The version can be changed with the
|
HttpCookie | back to summary |
---|---|
private HttpCookie(String name, String value, String header) |
HttpCookie | back to summary |
---|---|
pack-priv HttpCookie(String name, String value, String header, long creationTime) Package private for testing purposes. |
assignAttribute | back to summary |
---|---|
private static void assignAttribute(HttpCookie cookie, String attrName, String attrValue) |
clone | back to summary |
---|---|
public Object clone() Overrides java. Create and return a copy of this object. |
domainMatches | back to summary |
---|---|
public static boolean domainMatches(String domain, String host) The utility method to check whether a host name is in a domain or not. This concept is described in the cookie specification. To understand the concept, some terminologies need to be defined first: effective host name = hostname if host name contains dot Host A's name domain-matches host B's if:
A host isn't in a domain (RFC 2965 sec. 3.3.2) if:
Examples:
|
equals | back to summary |
---|---|
public boolean equals(Object obj) Overrides java. Test the equality of two HTTP cookies. The result is
|
equalsIgnoreCase | back to summary |
---|---|
private static boolean equalsIgnoreCase(String s, String t) |
expiryDate2DeltaSeconds | back to summary |
---|---|
private long expiryDate2DeltaSeconds(String dateString) |
getComment | back to summary |
---|---|
public String getComment() Returns the comment describing the purpose of this cookie, or
|
getCommentURL | back to summary |
---|---|
public String getCommentURL() Returns the comment URL describing the purpose of this cookie, or
|
getCreationTime | back to summary |
---|---|
pack-priv long getCreationTime() |
getDiscard | back to summary |
---|---|
public boolean getDiscard() Returns the discard attribute of the cookie
|
getDomain | back to summary |
---|---|
public String getDomain() Returns the domain name set for this cookie. The form of the domain name is set by RFC 2965. |
getMaxAge | back to summary |
---|---|
public long getMaxAge() Returns the maximum age of the cookie, specified in seconds. By default,
|
getName | back to summary |
---|---|
public String getName() Returns the name of the cookie. The name cannot be changed after creation.
|
getPath | back to summary |
---|---|
public String getPath() Returns the path on the server to which the browser returns this cookie. The cookie is visible to all subpaths on the server. |
getPortlist | back to summary |
---|---|
public String getPortlist() Returns the port list attribute of the cookie
|
getSecure | back to summary |
---|---|
public boolean getSecure() Returns
|
getValue | back to summary |
---|---|
public String getValue() Returns the value of the cookie. |
getVersion | back to summary |
---|---|
public int getVersion() Returns the version of the protocol this cookie complies with. Version 1 complies with RFC 2965/2109, and version 0 complies with the original cookie specification drafted by Netscape. Cookies provided by a browser use and identify the browser's cookie version.
|
guessCookieVersion | back to summary |
---|---|
private static int guessCookieVersion(String header) |
hasExpired | back to summary |
---|---|
public boolean hasExpired() Reports whether this HTTP cookie has expired or not.
|
hashCode | back to summary |
---|---|
public int hashCode() Overrides java. Returns the hash code of this HTTP cookie. The result is the sum of hash code value of three significant components of this cookie: name, domain, and path. That is, the hash code is the value of the expression: getName().toLowerCase().hashCode()
|
header | back to summary |
---|---|
private String header() |
isHttpOnly | back to summary |
---|---|
public boolean isHttpOnly() Returns
|
isToken | back to summary |
---|---|
private static boolean isToken(String value) |
parse | back to summary |
---|---|
public static List Constructs cookies from set-cookie or set-cookie2 header string. RFC 2965 section 3.2.2 set-cookie2 syntax indicates that one header line may contain more than one cookie definitions, so this is a static utility method instead of another constructor.
|
parse | back to summary |
---|---|
private static List |
parseInternal | back to summary |
---|---|
private static HttpCookie parseInternal(String header, boolean retainHeader) |
setComment | back to summary |
---|---|
public void setComment(String purpose) Specifies a comment that describes a cookie's purpose. The comment is useful if the browser presents the cookie to the user. Comments are not supported by Netscape Version 0 cookies.
|
setCommentURL | back to summary |
---|---|
public void setCommentURL(String purpose) Specifies a comment URL that describes a cookie's purpose. The comment URL is useful if the browser presents the cookie to the user. Comment URL is RFC 2965 only.
|
setDiscard | back to summary |
---|---|
public void setDiscard(boolean discard) Specify whether user agent should discard the cookie unconditionally. This is RFC 2965 only attribute.
|
setDomain | back to summary |
---|---|
public void setDomain(String pattern) Specifies the domain within which this cookie should be presented. The form of the domain name is specified by RFC 2965. A domain
name begins with a dot ( |
setHttpOnly | back to summary |
---|---|
public void setHttpOnly(boolean httpOnly) Indicates whether the cookie should be considered HTTP Only. If set to
|
setMaxAge | back to summary |
---|---|
public void setMaxAge(long expiry) Sets the maximum age of the cookie in seconds. A positive value indicates that the cookie will expire after that many seconds have passed. Note that the value is the maximum age when the cookie will expire, not the cookie's current age. A negative value means that the cookie is not stored persistently and will be deleted when the Web browser exits. A zero value causes the cookie to be deleted.
|
setPath | back to summary |
---|---|
public void setPath(String uri) Specifies a path for the cookie to which the client should return the cookie. The cookie is visible to all the pages in the directory you specify, and all the pages in that directory's subdirectories. A cookie's path must include the servlet that set the cookie, for example, /catalog, which makes the cookie visible to all directories on the server under /catalog. Consult RFC 2965 (available on the Internet) for more information on setting path names for cookies. |
setPortlist | back to summary |
---|---|
public void setPortlist(String ports) Specify the portlist of the cookie, which restricts the port(s) to which a cookie may be sent back in a Cookie header.
|
setSecure | back to summary |
---|---|
public void setSecure(boolean flag) Indicates whether the cookie should only be sent using a secure protocol, such as HTTPS or SSL. The default value is
|
setValue | back to summary |
---|---|
public void setValue(String newValue) Assigns a new value to a cookie after the cookie is created. If you use a binary value, you may want to use BASE64 encoding. With Version 0 cookies, values should not contain white space, brackets, parentheses, equals signs, commas, double quotes, slashes, question marks, at signs, colons, and semicolons. Empty values may not behave the same way on all browsers. |
setVersion | back to summary |
---|---|
public void setVersion(int v) Sets the version of the cookie protocol this cookie complies with. Version 0 complies with the original Netscape cookie specification. Version 1 complies with RFC 2965/2109.
|
splitMultiCookies | back to summary |
---|---|
private static List |
startsWithIgnoreCase | back to summary |
---|---|
private static boolean startsWithIgnoreCase(String s, String start) |
stripOffSurroundingQuote | back to summary |
---|---|
private static String stripOffSurroundingQuote(String str) |
toNetscapeHeaderString | back to summary |
---|---|
private String toNetscapeHeaderString() |
toRFC2965HeaderString | back to summary |
---|---|
private String toRFC2965HeaderString() |
toString | back to summary |
---|---|
public String toString() Overrides java. Constructs a cookie header string representation of this cookie, which is in the format defined by corresponding cookie specification, but without the leading "Cookie:" token. |
Modifier and Type | Method and Description |
---|---|
public void |
assign | back to summary |
---|---|
public void assign(HttpCookie cookie, String attrName, String attrValue) |