GeezerVison is showing docs.oracle.com — HttpCookie (Java Platform SE 8 )
Java™ Platform Standard Ed. 8
compact1, compact2, compact3
java.net
Class HttpCookie
-
-
Constructor Summary
Constructors
| Constructor |
Description |
HttpCookie(String name,
String value) |
Constructs a cookie with a specified name and value.
|
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods
| Modifier and Type |
Method |
Description |
Object |
clone() |
Create and return a copy of this object.
|
static boolean |
domainMatches(String domain,
String host) |
The utility method to check whether a host name is in a domain or not.
|
boolean |
equals(Object obj) |
Test the equality of two HTTP cookies.
|
String |
getComment() |
Returns the comment describing the purpose of this cookie, or
null if the cookie has no comment.
|
String |
getCommentURL() |
Returns the comment URL describing the purpose of this cookie, or
null if the cookie has no comment URL.
|
boolean |
getDiscard() |
Returns the discard attribute of the cookie
|
String |
getDomain() |
Returns the domain name set for this cookie.
|
long |
getMaxAge() |
Returns the maximum age of the cookie, specified in seconds.
|
String |
getName() |
Returns the name of the cookie.
|
String |
getPath() |
Returns the path on the server to which the browser returns this cookie.
|
String |
getPortlist() |
Returns the port list attribute of the cookie
|
boolean |
getSecure() |
Returns true if sending this cookie should be restricted to a
secure protocol, or false if the it can be sent using any
protocol.
|
String |
getValue() |
Returns the value of the cookie.
|
int |
getVersion() |
Returns the version of the protocol this cookie complies with.
|
boolean |
hasExpired() |
Reports whether this HTTP cookie has expired or not.
|
int |
hashCode() |
Returns the hash code of this HTTP cookie.
|
boolean |
isHttpOnly() |
Returns true if this cookie contains the HttpOnly
attribute.
|
static List<HttpCookie> |
parse(String header) |
Constructs cookies from set-cookie or set-cookie2 header string.
|
void |
setComment(String purpose) |
Specifies a comment that describes a cookie's purpose.
|
void |
setCommentURL(String purpose) |
Specifies a comment URL that describes a cookie's purpose.
|
void |
setDiscard(boolean discard) |
Specify whether user agent should discard the cookie unconditionally.
|
void |
setDomain(String pattern) |
Specifies the domain within which this cookie should be presented.
|
void |
setHttpOnly(boolean httpOnly) |
Indicates whether the cookie should be considered HTTP Only.
|
void |
setMaxAge(long expiry) |
Sets the maximum age of the cookie in seconds.
|
void |
setPath(String uri) |
Specifies a path for the cookie to which the client should return
the cookie.
|
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.
|
void |
setSecure(boolean flag) |
Indicates whether the cookie should only be sent using a secure protocol,
such as HTTPS or SSL.
|
void |
setValue(String newValue) |
Assigns a new value to a cookie after the cookie is created.
|
void |
setVersion(int v) |
Sets the version of the cookie protocol this cookie complies
with.
|
String |
toString() |
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.
|
-
-
Method Detail
-
parse
public static List<HttpCookie> parse(String header)
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.
- Parameters:
header - a String specifying the set-cookie header. The header
should start with "set-cookie", or "set-cookie2" token; or it
should have no leading token at all.
- Returns:
- a List of cookie parsed from header line string
- Throws:
IllegalArgumentException - if header string violates the cookie specification's syntax or
the cookie name contains illegal characters.
NullPointerException - if the header string is null
-
setComment
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.
- Parameters:
purpose - a String specifying the comment to display to the user
- See Also:
getComment()
-
getComment
public String getComment()
Returns the comment describing the purpose of this cookie, or
null if the cookie has no comment.
- Returns:
- a
String containing the comment, or null if none
- See Also:
setComment(java.lang.String)
-
setCommentURL
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.
- Parameters:
purpose - a String specifying the comment URL to display to the user
- See Also:
getCommentURL()
-
getCommentURL
public String getCommentURL()
Returns the comment URL describing the purpose of this cookie, or
null if the cookie has no comment URL.
- Returns:
- a
String containing the comment URL, or null
if none
- See Also:
setCommentURL(java.lang.String)
-
setPortlist
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.
- Parameters:
ports - a String specify the port list, which is comma separated
series of digits
- See Also:
getPortlist()
-
getSecure
public boolean getSecure()
Returns true if sending this cookie should be restricted to a
secure protocol, or false if the it can be sent using any
protocol.
- Returns:
false if the cookie can be sent over any standard
protocol; otherwise, true
- See Also:
setSecure(boolean)
-
setVersion
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.
- Parameters:
v - 0 if the cookie should comply with the original Netscape
specification; 1 if the cookie should comply with RFC 2965/2109
- Throws:
IllegalArgumentException - if v is neither 0 nor 1
- See Also:
getVersion()
-
isHttpOnly
public boolean isHttpOnly()
Returns true if this cookie contains the HttpOnly
attribute. This means that the cookie should not be accessible to
scripting engines, like javascript.
- Returns:
true if this cookie should be considered HTTPOnly
- See Also:
setHttpOnly(boolean)
-
hashCode
public int hashCode()
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()
+ getDomain().toLowerCase().hashCode()
+ getPath().hashCode()
- Overrides:
hashCode in class Object
- Returns:
- this HTTP cookie's hash code
- See Also:
Object.equals(java.lang.Object),
System.identityHashCode(java.lang.Object)
Java™ Platform Standard Ed. 8
Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
|