Class Cookie
- java.lang.Object
-
- org.exoplatform.common.http.client.Cookie
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
Cookie2
public class Cookie extends Object implements Serializable
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:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleandiscard()booleanequals(Object obj)Two cookies match if the name, path and domain match.Dateexpires()StringgetDomain()Return the domain this cookie is valid in.StringgetName()Return the name of this cookie.StringgetPath()Return the path this cookie is associated with.StringgetValue()Return the value of this cookie.booleanhasExpired()inthashCode()Hash up name, path and domain into new hash.booleanisHttpOnly()Return true if cookie have httponly activated.booleanisSecure()Return whether this cookie should only be sent over secure connections.protected static Cookie[]parse(String set_cookie, RoRequest req)Parses the Set-Cookie header into an array of Cookies.protected booleansendWith(RoRequest req)protected StringtoExternalForm()StringtoString()Create a string containing all the cookie fields.
-
-
-
Constructor Detail
-
Cookie
public Cookie(String name, String value, String domain, String path, Date expires, boolean secure)
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
protected Cookie(RoRequest req)
Useparse()to create cookies.- See Also:
parse(String, RoRequest)
-
-
Method Detail
-
parse
protected static Cookie[] parse(String set_cookie, RoRequest req) throws ProtocolException
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
public String getName()
Return the name of this cookie.
-
getValue
public String getValue()
Return the value of this cookie.
-
expires
public Date 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
public String getDomain()
Return the domain this cookie is valid in.
-
getPath
public String 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
protected boolean sendWith(RoRequest req)
- 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
public boolean equals(Object obj)
Two cookies match if the name, path and domain match.
-
toExternalForm
protected String toExternalForm()
- Returns:
- a string suitable for sending in a Cookie header.
-
-