gov.llnl.babel.url.cookie
public class Cookie extends java.lang.Object implements java.io.Serializable
Constructor and Description |
---|
Cookie(java.lang.String name,
java.lang.String value)
The basic cookie constructor (or should I say cutter?).
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
decodeValue(java.lang.String value)
Unquote special characters in
value . |
static java.lang.String |
effectiveHostname(java.lang.String hostname)
Return the effective host name of a host name.
|
static java.lang.String |
encodeValue(java.lang.String value)
Quote special characters in
value . |
boolean |
equals(Cookie c)
Return true if two cookies are equal.
|
java.lang.String |
getComment()
Return the comment attribute of the cookie.
|
java.lang.String |
getDomain()
Return the domain of this cookie.
|
java.util.Date |
getExpiration()
Return the expiration date of the cookie.
|
int |
getMaxAge()
Return the maximum age attribute for the cookie.
|
java.lang.String |
getName()
Return the name of the cookie.
|
java.lang.String |
getPath()
Return the path attribute of the cookie.
|
java.lang.String |
getPorts()
Return the ports that the cookie is for.
|
java.lang.String |
getUrlComment()
Return the URL comment attribute of the cookie.
|
java.lang.String |
getValue()
Return the value of the cookie.
|
java.lang.String |
getVersion()
Return the cookie specification version number.
|
boolean |
hasExpired(long currentTime)
Check if the cookie has expired.
|
boolean |
hasValidDomain(java.lang.String hostname)
Check whether the domain name can be used by a particular host.
|
boolean |
isDiscardable()
Indicate whether the cookie should be discarded when the user agent
exits.
|
boolean |
isPortAllowed(int port)
Return
true iff port is allowed to
send/receive this cookie. |
boolean |
isRelevant(java.lang.String hostname,
java.lang.String path,
int port)
Check if the cookie should be sent with a particular request.
|
boolean |
isSecure()
Indicate whether the cookie is intended for secure connections only.
|
void |
setComment(java.lang.String comment)
Change the comment attribute of the cookie.
|
void |
setDiscardable(boolean discard)
Conditionally set the discard attribute of the cookie.
|
void |
setDomain(java.lang.String domain)
Set the domain of the request.
|
void |
setMaxAge(int maxAge,
java.util.Date created)
Set the maximum age and expiration date of the cookie.
|
void |
setPath(java.lang.String path)
Set the path.
|
void |
setPorts(java.lang.String ports)
Set the ports that are allowed to get the cookie.
|
void |
setSecure(boolean secure)
Conditionally set the secure attribute of the cookie.
|
void |
setUrlComment(java.lang.String comment)
Change the URL comment attribute of the cookie.
|
void |
setValue(java.lang.String value)
Change the value of the cookie.
|
void |
setVersion(java.lang.String version)
Set the version of the cookie protocol.
|
java.lang.String |
toString()
Create a string suitable for including in a HTTP "Cookie:" header.
|
static boolean |
validPortList(java.lang.String ports)
Returns
true iff the port list is a valid list of
comma separated integers. |
static boolean |
validToken(java.lang.String tok)
Check if
tok is a valid token as defined by the
HTTP/1.1 spec. |
static boolean |
validValue(java.lang.String value)
Return true if the string is valid as a cookie attribute value.
|
public Cookie(java.lang.String name, java.lang.String value) throws CookieCrumbleException
name
- The cookie's name. This should be a sequence of
non-special, non-whitespace characters (according to
the spec.value
- The cookie's value. This should be encoded as
it does into a HTTP/1.1 header.CookieCrumbleException
- indicates that name or value is illegal.public static java.lang.String encodeValue(java.lang.String value)
value
. When you're putting
certain value fields into a HTTP/1.1 header, the double quote and
backslash characters must be quoted with a backslash.value
- a string of text."
or \
characters
encoded.public static java.lang.String decodeValue(java.lang.String value)
value
. When you take
a value field from a HTTP/1.1 header, you must remove the
backslash quoting to get the real value.value
- a string of text."
or \
characters
encoded.public static boolean validToken(java.lang.String tok)
tok
is a valid token as defined by the
HTTP/1.1 spec.tok
- a string that may or may not be a valid token.true
means tok
is a valid
HTTP/1.1 token; false
means tok
is not a valid token.public static boolean validValue(java.lang.String value)
TEXT
in RFC 2616 (the HTTP/1.1 spec).true
means that the attribute value is
acceptable.public static boolean validPortList(java.lang.String ports)
true
iff the port list is a valid list of
comma separated integers.true
means that the attribute value is
acceptable.public static java.lang.String effectiveHostname(java.lang.String hostname)
hostname
doesn't have any periods in it, ".local" is
appended.hostname
- the original host namehostname
doesn't have any periods in it,
hostname with ".local" appended is returned; otherwise, hostname is
return unmodified.public java.lang.String getName()
public java.lang.String getValue()
public java.lang.String getComment()
null
indicating that the cookie contains no comment.null
or a valid string containing the comment
attribute.public java.lang.String getUrlComment()
null
indicating that the cookie contains no URL comment.null
or a valid string containing the URL comment
attribute.public java.lang.String getDomain()
null
.public int getMaxAge()
public java.util.Date getExpiration()
null
if no maximum age setting; otherwise,
the date and time that the cookie should cease to exist.public java.lang.String getPath()
public java.lang.String getPorts()
null
(means no restriction on ports) or a
comma separated list of ports.public boolean isSecure()
true
means the cookie should only be sent on
a secure channel; false
means the cookie can
be sent on secure on unsecured channels.public boolean isDiscardable()
true
means that the cookie should be discarded
when the user agent exits; false
means that the cookie
should be persisted until it expires.public java.lang.String getVersion()
null
if the client hasn't specified the cookie
specification version; otherwise a string holding the
cookie spec. version.public boolean hasValidDomain(java.lang.String hostname)
public void setValue(java.lang.String value) throws CookieCrumbleException
value
- This is the value of the cookie. If the value is
coming from an incomming HTTP/1.1 header, it
should be run through decodeValue
before
passing it into here.CookieCrumbleException
- indicates that the value is not legalpublic void setComment(java.lang.String comment) throws CookieCrumbleException
comment
- This is the cookie's comment. If the comment is
coming from an incomming HTTP/1.1 header, it
should be run through decodeValue
before
passing it into here.CookieCrumbleException
- indicates that the comment is not a legal valuepublic void setUrlComment(java.lang.String comment) throws CookieCrumbleException
comment
- This is the cookie's URL comment. If the comment is
coming from an incomming HTTP/1.1 header, it
should be run through decodeValue
before
passing it into here.CookieCrumbleException
- The URL is not valid.public void setDomain(java.lang.String domain) throws CookieCrumbleException
domain
- this should be a domain name, a hostname or .local.CookieCrumbleException
- indicates that the domain is not acceptablepublic void setMaxAge(int maxAge, java.util.Date created) throws CookieCrumbleException
maxAge
- a non-negative integer value indicating the
maximum age in secondscreated
- best estimate of when the cookie was createdCookieCrumbleException
- indicates that maxAge or created was invalidpublic void setPath(java.lang.String path) throws CookieCrumbleException
path
- the leading elements of a URL path that limits the
scope of the cookieCookieCrumbleException
- indicates that the path is invalidpublic void setPorts(java.lang.String ports) throws CookieCrumbleException
ports
- a list of ports that are allowed to send/receive the
cookie.CookieCrumbleException
- indicates that the path is invalidpublic void setSecure(boolean secure)
secure
- true
will make the cookie require a secure
channel; false
will allow the cookie
to be communicated via unsecure channels.public void setDiscardable(boolean discard)
discard
- true
will mark the cookie to be discarded
while the user agent exits; false
will
mark the cookie to be persisted by its environment.public void setVersion(java.lang.String version)
version
- Set the version of the protocol used by this cookie.public boolean hasExpired(long currentTime)
currentTime
- use this as the current time in milliseconds since
January 1, 1970.true
means the cookie's expiration time has
past; false
means the cookie has not expired.public boolean isPortAllowed(int port)
true
iff port
is allowed to
send/receive this cookie.port
- the port whose access should be checked.true
means that port
may receive
the cookie; false
means port
must not receive the cookie.public boolean equals(Cookie c)
public boolean isRelevant(java.lang.String hostname, java.lang.String path, int port)
hostname
- The hostname the sent or may receive the cookie.path
- The filename of the request.port
- The port number of the request.true
means the cookie should be sent to the
server; false
means the cookie must
not be sent to the server.public java.lang.String toString()
toString
in class java.lang.Object