Class Cookie
java.lang.Object
org.exoplatform.common.http.client.Cookie
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
Cookie2
This class represents an http cookie as specified in Netscape's
cookie spec; however, because not even Netscape follows their own spec,
and because very few folks out there actually read specs but instead just
look whether Netscape accepts their stuff, the Set-Cookie header field parser
actually tries to follow what Netscape has implemented, instead of what the
spec says. Additionally, the parser it will also recognize the Max-Age
parameter from rfc-2109, as
that uses the same header field (Set-Cookie).
Some notes about how Netscape (4.7) parses:
- Quoting: only quotes around the expires value are recognized as such; quotes around any other value are treated as part of the value.
- White space: white space around names and values is ignored
- Default path: if no path parameter is given, the path defaults to the path in the request-uri up to, but not including, the last '/'. Note that this is entirely different from what the spec says.
- Commas and other delimiters: Netscape just parses until the next ';'. This means will allow commas etc inside values.
- Since:
- V0.3
- Version:
- 0.3-3 06/05/2001
- Author:
- Ronald Tschal�r
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleandiscard()booleanTwo cookies match if the name, path and domain match.expires()Return the domain this cookie is valid in.getName()Return the name of this cookie.getPath()Return the path this cookie is associated with.getValue()Return the value of this cookie.booleaninthashCode()Hash up name, path and domain into new hash.booleanReturn true if cookie have httponly activated.booleanisSecure()Return whether this cookie should only be sent over secure connections.protected static Cookie[]Parses the Set-Cookie header into an array of Cookies.protected booleanprotected StringtoString()Create a string containing all the cookie fields.
-
Field Details
-
name
-
value
-
expires
-
domain
-
path
-
secure
protected boolean secure -
httpOnly
protected boolean httpOnly
-
-
Constructor Details
-
Cookie
Create a cookie.- Parameters:
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 this cookie expires, null if at end of sessionsecure- if true this cookie will only be over secure connections- Throws:
NullPointerException- if name, value, domain, or path is null- Since:
- V0.3-1
-
Cookie
Useparse()to create cookies.- See Also:
-
-
Method Details
-
parse
Parses the Set-Cookie header into an array of Cookies.- Parameters:
set_cookie- the Set-Cookie header received from the serverreq- the request used- Returns:
- an array of Cookies as parsed from the Set-Cookie header
- Throws:
ProtocolException- if an error occurs during parsing
-
getName
Return the name of this cookie. -
getValue
Return the value of this cookie. -
expires
- Returns:
- the expiry date of this cookie, or null if none set.
-
discard
public boolean discard()- Returns:
- true if the cookie should be discarded at the end of the session; false otherwise
-
getDomain
Return the domain this cookie is valid in. -
getPath
Return the path this cookie is associated with. -
isSecure
public boolean isSecure()Return whether this cookie should only be sent over secure connections. -
isHttpOnly
public boolean isHttpOnly()Return true if cookie have httponly activated. -
hasExpired
public boolean hasExpired()- Returns:
- true if this cookie has expired
-
sendWith
- Parameters:
req- the request to be sent- Returns:
- true if this cookie should be sent with the request
-
hashCode
public int hashCode()Hash up name, path and domain into new hash. -
equals
Two cookies match if the name, path and domain match. -
toExternalForm
- Returns:
- a string suitable for sending in a Cookie header.
-
toString
Create a string containing all the cookie fields. The format is that used in the Set-Cookie header.
-