|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sonalb.net.http.cookie.RFC2965CookieParser
public class RFC2965CookieParser
Implementation for CookieParser that conforms to cookie specification RFC-2965.
Constructor Summary | |
---|---|
RFC2965CookieParser()
|
Method Summary | |
---|---|
boolean |
allowedCookie(Cookie c,
java.net.URL url)
Checks whether a request to the given URL is allowed to return the specified Cookie. |
static boolean |
domainMatch(java.net.URL url,
java.lang.String domain)
Performs "domain matching" of URL host/domain to cookie domain, for Version 1 cookies as specified by RFC 2965. |
Header |
getCookieHeaders(CookieJar cj)
Converts the Cookie s in the CookieJar
to a set of headers suitable to be sent along with an HTTP request. |
static boolean |
isRFC2965CookieString(java.lang.String c)
Determines whether a cookie string is for Version 0 or Version 1 cookie. |
CookieJar |
parseCookies(Header header,
java.net.URL url)
Converts the headers in an HTTP response into a CookieJar
of Cookie objects. |
static CookieJar |
parseSetCookieV0(Header responseHeader,
java.net.URL url,
boolean bStrict)
Parses headers into Version 1 Cookies. |
static CookieJar |
parseSetCookieV1(Header responseHeader,
java.net.URL url,
boolean bStrict)
Parses headers into Version 1 Cookies. |
static Cookie |
parseSingleCookieV0(java.lang.String s,
java.net.URL url,
boolean bStrict)
Converts a single cookie-string into a Cookie object, for Version 0 |
static Cookie |
parseSingleCookieV1(java.lang.String s,
java.net.URL url,
boolean bStrict)
Converts a single cookie-string into a Cookie object, for Version 1 |
static boolean |
pathMatch(java.net.URL url,
java.lang.String path)
Performs "path matching" of URL to cookie path, as specified by RFC 2965. |
static boolean |
portMatch(java.net.URL url,
java.lang.String portList)
Performs "port matching" of URL to cookie portlist, for Version 1 cookies, as specified by RFC 2965. |
boolean |
sendCookieWithURL(Cookie c,
java.net.URL url,
boolean bRespectExpires)
Determines whether a Cookie is eligible to be sent alongwith the request
for a given URL . |
static CookieJar |
sortCookiesByPathSpecificity(CookieJar cj)
Sorts the Cookie s in the input CookieJar , with the cookie
having most specific path attribute first. |
static boolean |
tailMatch(java.net.URL url,
java.lang.String domain)
Performs "tail matching" of URL host/domain to cookie domain, for Version 0 cookies as specified by Netscape's draft. |
static java.lang.String |
toCookieHeaderForm(Cookie c,
boolean bIncludeVersion)
Converts a single Cookie to a form suitable for sending with a request, back to the server. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public RFC2965CookieParser()
Method Detail |
---|
public Header getCookieHeaders(CookieJar cj)
CookieParser
Cookie
s in the CookieJar
to a set of headers suitable to be sent along with an HTTP request.
getCookieHeaders
in interface CookieParser
public boolean allowedCookie(Cookie c, java.net.URL url)
CookieParser
allowedCookie
in interface CookieParser
public CookieJar parseCookies(Header header, java.net.URL url) throws MalformedCookieException
CookieParser
CookieJar
of Cookie
objects.
parseCookies
in interface CookieParser
MalformedCookieException
public boolean sendCookieWithURL(Cookie c, java.net.URL url, boolean bRespectExpires)
Cookie
is eligible to be sent alongwith the request
for a given URL
. This method may or may not take into consideration the
lifetime (indicated by cookie parameters). It discerns between Version 0 (Netscape)
and Version 1 (RFC 2965) cookies. For Version 0 cookies, the relevant portion of
Netscape's draft:"When searching the cookie list for valid cookies, a comparison of the domain attributes of the cookie is made with the Internet domain name of the host from which the URL will be fetched. If there is a tail match, then the cookie will go through path matching to see if it should be sent."
For Version 1 cookies, the relevant portion of Netscape's draft:
"The user agent applies the following rules to choose applicable cookie-values to send in Cookie request headers from among all the cookies it has received.
Domain Selection
The origin server's effective host name MUST domain-match the Domain
attribute of the cookie.
Port Selection
There are three possible behaviors, depending on the Port
attribute in the Set-Cookie2 response header:
1. By default (no Port attribute), the cookie MAY be sent to
any port.
2. If the attribute is present but has no value (e.g., Port), the
cookie MUST only be sent to the request-port it was received from.
3. If the attribute has a port-list, the cookie MUST only be
returned if the new request-port is one of those listed in port-list.
Path Selection
The request-URI MUST path-match the Path attribute of the cookie.
Max-Age Selection
Cookies that have expired should have been discarded and thus are
not forwarded to an origin server."
Note: For both Versions 0 and 1 cookies, if the cookie is marked as "secure", it can be sent only over a secure transport. This implementation considers HTTPS and SHTTP protocols as secure.
sendCookieWithURL
in interface CookieParser
c
- the Cookie
to be tested.url
- the URL
for which to test.bRespectExpires
- whether or not to take expiry information into consideration.
java.lang.IllegalArgumentException
- Thrown if the input Cookie
is not valid, that is,
it is incomplete.pathMatch(java.net.URL, java.lang.String)
,
tailMatch(java.net.URL, java.lang.String)
,
domainMatch(java.net.URL, java.lang.String)
,
portMatch(java.net.URL, java.lang.String)
,
Cookie.hasExpired()
,
Cookie.isValid()
public static CookieJar sortCookiesByPathSpecificity(CookieJar cj)
Cookie
s in the input CookieJar
, with the cookie
having most specific path attribute first. This is used while determining the order in
which cookies must be sent back to the server.
Note: The input CookieJar
is NOT modified, instead, a new CookieJar
is returned with the sorted Cookies.
cj
- the CookieJar with the cookies to be sorted.CookieJar
public static boolean pathMatch(java.net.URL url, java.lang.String path)
URL
's path
is obtained by URL.getPath()
. The relevant portion of RFC 2965 :"For two strings that represent paths, P1 and P2, P1 path-matches P2 if P2 is a prefix of P1 (including the case where P1 and P2 string-compare equal). Thus, the string /tec/waldo path-matches /tec."
url
- the URL
which must be matched.path
- the cookie path.
true
if the URL path-matched the cookie path; false
otherwise.URL
public static boolean tailMatch(java.net.URL url, java.lang.String domain)
URL
's host is obtained by URL.getHost()
. The relevant portion of Netscape's draft :""Tail matching" means that domain attribute is matched against the tail of the fully qualified domain name of the host. A domain attribute of "acme.com" would match host names "anvil.acme.com" as well as "shipping.crate.acme.com".
Only hosts within the specified domain can set a cookie for a domain and domains must have at least two (2) or three (3) periods in them to prevent domains of the form: ".com", ".edu", and "va.us". Any domain that fails within one of the seven special top level domains listed below only require two periods. Any other domain requires at least three. The seven special top level domains are: "COM", "EDU", "NET", "ORG", "GOV", "MIL", and "INT"".
url
- the URL
which must be matched.domain
- the cookie domain.
true
if the URL tail-matched the cookie domain; false
otherwise.URL
public static boolean domainMatch(java.net.URL url, java.lang.String domain)
URL
's host is obtained by URL.getHost()
. The relevant portion of RFC 2965 :"Host names can be specified either as an IP address or a HDN [host domain name] string. Sometimes we compare one host name with another. (Such comparisons SHALL be case-insensitive.) Host A's name domain-matches host B's if
* their host name strings string-compare equal; or * A is a HDN string and has the form NB, where N is a non-empty name string, B has the form .B', and B' is a HDN string. (So, x.y.com domain-matches .Y.com but not Y.com.)Note that domain-match is not a commutative operation: a.b.c.com domain-matches .c.com, but not the reverse."
url
- the URL
which must be matched.domain
- the cookie domain.
true
if the URL domain-matched the cookie domain; false
otherwise.URL
public static final boolean portMatch(java.net.URL url, java.lang.String portList)
URL
port-matches the given portlist, if the port returned by URL.getPort()
exists in the
portlist. The portlist itself is a comma-separated list of allowed ports for that cookie. If URL.getPort()
returns a value less than 0, the default port of 80 is assumed.
url
- the URL
which must be matched.portList
- the comma-separated list of acceptable ports.
true
if the URL port exists in portList, or if portList is empty; false
otherwise.URL
public static java.lang.String toCookieHeaderForm(Cookie c, boolean bIncludeVersion)
c
- the Cookie to be convertedbIncludeVersion
- whether the version number should be included
public static final CookieJar parseSetCookieV1(Header responseHeader, java.net.URL url, boolean bStrict) throws MalformedCookieException
MalformedCookieException
public static final CookieJar parseSetCookieV0(Header responseHeader, java.net.URL url, boolean bStrict) throws MalformedCookieException
MalformedCookieException
public static Cookie parseSingleCookieV0(java.lang.String s, java.net.URL url, boolean bStrict) throws MalformedCookieException
MalformedCookieException
public static Cookie parseSingleCookieV1(java.lang.String s, java.net.URL url, boolean bStrict) throws MalformedCookieException
MalformedCookieException
public static boolean isRFC2965CookieString(java.lang.String c) throws MalformedCookieException
MalformedCookieException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |