|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.commons.httpclient.NameValuePair | +--org.apache.commons.httpclient.Cookie
An HTTP "magic-cookie", as specified in RFC 2109.
Constructor Summary | |
Cookie()
Create a cookie. |
|
Cookie(String domain,
String name,
String value)
Create a cookie. |
|
Cookie(String domain,
String name,
String value,
String path,
Date expires,
boolean secure)
Create a cookie. |
|
Cookie(String domain,
String name,
String value,
String path,
int maxAge,
boolean secure)
Create a cookie. |
Method Summary | |
int |
compare(Object o1,
Object o2)
Compares two cookies to determine order for cookie header. |
static Header |
createCookieHeader(String domain,
int port,
String path,
boolean secure,
Cookie[] cookies)
Deprecated. use CookieSpec interface |
static Header |
createCookieHeader(String domain,
int port,
String path,
boolean secure,
Date now,
Cookie[] cookies)
Deprecated. use CookieSpec interface |
static Header |
createCookieHeader(String domain,
String path,
boolean secure,
Cookie[] cookies)
Deprecated. use CookieSpec interface |
static Header |
createCookieHeader(String domain,
String path,
Cookie[] cookies)
Deprecated. use CookieSpec interface |
boolean |
equals(Object obj)
Two cookies are equal if the name, path and domain match. |
String |
getComment()
Returns the comment describing the purpose of this cookie, or null if no such comment has been defined. |
String |
getDomain()
Returns my domain. |
Date |
getExpiryDate()
Returns my expiration Date , or null
if none exists. |
String |
getPath()
|
boolean |
getSecure()
|
int |
getVersion()
|
int |
hashCode()
Returns a hash code in keeping with the Object.hashCode() general hashCode contract. |
boolean |
isDomainAttributeSpecified()
Returns true if cookie's domain was set via a Domain attribute in the set-cookie header. |
boolean |
isExpired()
Return true if this cookie has expired. |
boolean |
isExpired(Date now)
Return true if this cookie has expired according to the time passed in. |
boolean |
isPathAttributeSpecified()
Returns true if cookie's path was set via a Path attribute in the set-cookie header. |
boolean |
isPersistent()
Returns false if I should be discarded at the end of the "session"; true otherwise. |
boolean |
matches(String domain,
int port,
String path,
boolean secure)
Deprecated. use CookieSpec interface |
boolean |
matches(String domain,
int port,
String path,
boolean secure,
Date date)
Deprecated. use CookieSpec interface |
static Cookie[] |
parse(String domain,
int port,
String path,
boolean secure,
Header setCookie)
Deprecated. use CookieSpec interface |
static Cookie[] |
parse(String domain,
int port,
String path,
Header setCookie)
Deprecated. use CookieSpec interface |
static Cookie[] |
parse(String domain,
String path,
boolean secure,
Header setCookie)
Deprecated. use CookieSpec interface |
static Cookie[] |
parse(String domain,
String path,
Header setCookie)
Deprecated. use CookieSpec interface |
void |
setComment(String comment)
If a user agent (web browser) presents this cookie to a user, the cookie's purpose will be described using this comment. |
void |
setDomain(String domain)
Sets my domain. |
void |
setDomainAttributeSpecified(boolean value)
Indicates whether the cookie had a domain specified in a Domain attribute in the set-cookie header. |
void |
setExpiryDate(Date expiryDate)
Expiration setter. |
void |
setPath(String path)
Sets my path. |
void |
setPathAttributeSpecified(boolean value)
Indicates whether the cookie had a path specified in a Path attribute in the set-cookie header. |
void |
setSecure(boolean secure)
Set my secure flag. |
void |
setVersion(int version)
Set the version of the HTTP cookie specification I report. |
String |
toExternalForm()
Return a string suitable for sending in a Cookie header. |
String |
toString()
Return a String representation of me. |
Methods inherited from class org.apache.commons.httpclient.NameValuePair |
getName,
getValue,
setName,
setValue |
Methods inherited from class java.lang.Object |
clone,
finalize,
getClass,
notify,
notifyAll,
wait,
wait,
wait |
Constructor Detail |
public Cookie()
public Cookie(String domain, String name, String value)
name
- the cookie namevalue
- the cookie valuedomain
- the host this cookie will be sent topublic Cookie(String domain, String name, String value, String path, Date expires, boolean secure)
name
- the cookie namevalue
- the cookie valuedomain
- the host this cookie will be sent topath
- the path prefix for which this cookie will be sentexpires
- the Date
at which this cookie expires,
or null if the cookie expires at the end
of the sessionsecure
- if true this cookie will only be sent over secure
connectionspublic Cookie(String domain, String name, String value, String path, int maxAge, boolean secure)
name
- the cookie namevalue
- the cookie valuedomain
- the host this cookie will be sent topath
- the path prefix for which this cookie will be sentmaxAge
- the number of seconds for which this cookie is valid.
maxAge is expected to be a non-negative number.
-1 signifies that the cookie should never expire.secure
- if true this cookie will only be sent over secure
connectionsMethod Detail |
public String getComment()
setComment(String)
public void setComment(String comment)
getComment()
public Date getExpiryDate()
Date
, or null
if none exists.
Note: the object returned by this method is considered immutable. Changing it (e.g. using setTime()) could result in undefined behaviour. Do so at your peril.
Date
, or null.setExpiryDate(java.util.Date)
public void setExpiryDate(Date expiryDate)
Netscape's original proposal defined an Expires header that took
a date value in a fixed-length variant format in place of Max-Age:
Wdy, DD-Mon-YY HH:MM:SS GMT
Note that the Expires date format contains embedded spaces, and that
"old" cookies did not have quotes around values. Clients that
implement to this specification should be aware of "old" cookies and
Expires.
Note: the object returned by this method is considered immutable. Changing it (e.g. using setTime()) could result in undefined behaviour. Do so at your peril.
expiryDate
- the Date
after which this cookie is no longer valid.getExpiryDate()
public boolean isPersistent()
public String getDomain()
setDomain(java.lang.String)
public void setDomain(String domain)
I should be presented only to hosts satisfying this domain name pattern. Read RFC 2109 for specific details of the syntax. Briefly, a domain name name begins with a dot (".foo.com") and means that hosts in that DNS zone ("www.foo.com", but not "a.b.foo.com") should see the cookie. By default, cookies are only returned to the host which saved them.
getDomain()
public String getPath()
setPath(java.lang.String)
public void setPath(String path)
I should be presented only with requests beginning with this path. See RFC 2109 for a specification of the default behaviour. Basically, URLs in the same "directory" as the one which set the cookie, and in subdirectories, can all see the cookie unless a different path is set.
getPath()
public boolean getSecure()
true
if this cookie should only be sent over secure connections.setSecure(boolean)
public void setSecure(boolean secure)
When true the cookie should only be sent using a secure protocol (https). This should only be set when the cookie's originating server used a secure protocol to set the cookie's value.
getSecure()
public int getVersion()
setVersion(int)
public void setVersion(int version)
The current implementation only sends version 1 cookies. (See RFC 2109 for details.)
getVersion()
public boolean isExpired()
public boolean isExpired(Date now)
now
- The current time.public void setPathAttributeSpecified(boolean value)
value
- True if the cookie's path came from a Path attribute.isPathAttributeSpecified()
public boolean isPathAttributeSpecified()
setPathAttributeSpecified(boolean)
public void setDomainAttributeSpecified(boolean value)
value
- True if the cookie's domain came from a Domain attribute.isDomainAttributeSpecified()
public boolean isDomainAttributeSpecified()
setDomainAttributeSpecified(boolean)
public int hashCode()
Object.hashCode()
general hashCode contract.public boolean equals(Object obj)
obj
- The object to compare against.public String toExternalForm()
public boolean matches(String domain, int port, String path, boolean secure, Date date)
CookieSpec
interface
domain
- the host to which the request is being submittedport
- the port to which the request is being submitted (currently
ignored)path
- the path to which the request is being submittedsecure
- true if the request is using the HTTPS protocoldate
- the time at which the request is submittedpublic boolean matches(String domain, int port, String path, boolean secure)
CookieSpec
interface
domain
- the host to which the request is being submittedport
- the port to which the request is being submitted (currently
ignored)path
- the path to which the request is being submittedsecure
- True if this cookie has the secure flag setpublic static Header createCookieHeader(String domain, String path, Cookie[] cookies)
CookieSpec
interface
If no cookies match, returns null.
domain
- The domainpath
- The pathcookies
- The cookies to usepublic static Header createCookieHeader(String domain, String path, boolean secure, Cookie[] cookies) throws IllegalArgumentException
CookieSpec
interface
If no cookies match, returns null.
domain
- The domainpath
- The pathsecure
- True if this cookie has the secure flag setcookies
- The cookies to use.public static Header createCookieHeader(String domain, int port, String path, boolean secure, Cookie[] cookies) throws IllegalArgumentException
CookieSpec
interface
If no cookies match, returns null.
domain
- The domainport
- The portpath
- The pathsecure
- True if this cookie has the secure flag setcookies
- The cookies to use.public static Header createCookieHeader(String domain, int port, String path, boolean secure, Date now, Cookie[] cookies) throws IllegalArgumentException
CookieSpec
interface
If no cookies match, returns null.
domain
- The domainport
- The portpath
- The pathsecure
- True if this cookie has the secure flag setnow
- The date to check for expirycookies
- The cookies to use.public int compare(Object o1, Object o2)
Compares two cookies to determine order for cookie header.
Most specific should be first.
This method is implemented so a cookie can be used as a comparator for a SortedSet of cookies. Specifically it's used above in the createCookieHeader method.
The compare only compares the path of the cookie, see section 4.3.4 of RFC2109
o1
- The first object to be comparedo2
- The second object to be comparedComparator.compare(Object,Object)
public String toString()
String
representation of me.toExternalForm()
public static Cookie[] parse(String domain, int port, String path, Header setCookie) throws HttpException, IllegalArgumentException
CookieSpec
interface
Header
into an array of
Cookies, assuming that the cookies were recieved
on an insecure channel.domain
- the domain from which the Header
was receivedport
- the port from which the Header
was received
(currently ignored)path
- the path from which the Header
was receivedsetCookie
- the Set-Cookie Header
received from the
serverHeader
public static Cookie[] parse(String domain, String path, Header setCookie) throws HttpException, IllegalArgumentException
CookieSpec
interface
Header
into an array of
Cookies, assuming that the cookies were recieved
on an insecure channel.domain
- the domain from which the Header
was receivedpath
- the path from which the Header
was receivedsetCookie
- the Set-Cookie Header
received from the
serverHeader
public static Cookie[] parse(String domain, String path, boolean secure, Header setCookie) throws HttpException, IllegalArgumentException
CookieSpec
interface
Header
into an array of
Cookies.domain
- the domain from which the Header
was receivedpath
- the path from which the Header
was receivedsecure
- true when the header was recieved over a secure
channelsetCookie
- the Set-Cookie Header
received from the
serverHeader
public static Cookie[] parse(String domain, int port, String path, boolean secure, Header setCookie) throws HttpException
CookieSpec
interface
Header
into an array of
Cookies.
The syntax for the Set-Cookie response header is:
set-cookie = "Set-Cookie:" cookies cookies = 1#cookie cookie = NAME "=" VALUE * (";" cookie-av) NAME = attr VALUE = value cookie-av = "Comment" "=" value | "Domain" "=" value | "Max-Age" "=" value | "Path" "=" value | "Secure" | "Version" "=" 1*DIGIT
domain
- the domain from which the Header
was receivedport
- The port from which the Header
was received.path
- the path from which the Header
was receivedsecure
- true when the Header
was received over
HTTPSsetCookie
- the Set-Cookie Header
received from
the serverHeader
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |