Class RFC2965Spec
- java.lang.Object
-
- org.apache.commons.httpclient.cookie.CookieSpecBase
-
- org.apache.commons.httpclient.cookie.RFC2965Spec
-
- All Implemented Interfaces:
CookieSpec,CookieVersionSupport
public class RFC2965Spec extends CookieSpecBase implements CookieVersionSupport
RFC 2965 specific cookie management functions.
- Since:
- 3.1
- Author:
- jain.samit@gmail.com (Samit Jain)
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringSET_COOKIE2_KEYCookie Response Header name for cookies processed by this spec.-
Fields inherited from class org.apache.commons.httpclient.cookie.CookieSpecBase
LOG
-
Fields inherited from interface org.apache.commons.httpclient.cookie.CookieSpec
PATH_DELIM, PATH_DELIM_CHAR
-
-
Constructor Summary
Constructors Constructor Description RFC2965Spec()Default constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleandomainMatch(java.lang.String host, java.lang.String domain)Performs domain-match as defined by the RFC2965.protected CookieAttributeHandlerfindAttribHandler(java.lang.String name)Finds an attribute handlerCookieAttributeHandlerfor the given attribute.java.lang.StringformatCookie(Cookie cookie)Return a string suitable for sending in a "Cookie" header as defined in RFC 2965java.lang.StringformatCookies(Cookie[] cookies)Create a RFC 2965 compliant "Cookie" header value containing allCookies suitable for sending in a "Cookie" headerprotected CookieAttributeHandlergetAttribHandler(java.lang.String name)Gets attribute handlerCookieAttributeHandlerfor the given attribute.protected java.util.IteratorgetAttribHandlerIterator()intgetVersion()HeadergetVersionHeader()booleanmatch(java.lang.String host, int port, java.lang.String path, boolean secure, Cookie cookie)Return true if the cookie should be submitted with a request with given attributes, false otherwise.Cookie[]parse(java.lang.String host, int port, java.lang.String path, boolean secure, java.lang.String header)Parses the Set-Cookie value into an array of Cookies.Cookie[]parse(java.lang.String host, int port, java.lang.String path, boolean secure, Header header)Parses the Set-Cookie2 value into an array of Cookies.voidparseAttribute(NameValuePair attribute, Cookie cookie)Parse RFC 2965 specific cookie attribute and update the corresponsingCookieproperties.protected voidregisterAttribHandler(java.lang.String name, CookieAttributeHandler handler)voidvalidate(java.lang.String host, int port, java.lang.String path, boolean secure, Cookie cookie)Performs RFC 2965 compliantCookievalidation-
Methods inherited from class org.apache.commons.httpclient.cookie.CookieSpecBase
formatCookieHeader, formatCookieHeader, getValidDateFormats, match, pathMatch, setValidDateFormats
-
-
-
-
Field Detail
-
SET_COOKIE2_KEY
public static final java.lang.String SET_COOKIE2_KEY
Cookie Response Header name for cookies processed by this spec.- See Also:
- Constant Field Values
-
-
Method Detail
-
registerAttribHandler
protected void registerAttribHandler(java.lang.String name, CookieAttributeHandler handler)
-
findAttribHandler
protected CookieAttributeHandler findAttribHandler(java.lang.String name)
Finds an attribute handlerCookieAttributeHandlerfor the given attribute. Returns null if no attribute handler is found for the specified attribute.- Parameters:
name- attribute name. e.g. Domain, Path, etc.- Returns:
- an attribute handler or null
-
getAttribHandler
protected CookieAttributeHandler getAttribHandler(java.lang.String name)
Gets attribute handlerCookieAttributeHandlerfor the given attribute.- Parameters:
name- attribute name. e.g. Domain, Path, etc.- Throws:
java.lang.IllegalStateException- if handler not found for the specified attribute.
-
getAttribHandlerIterator
protected java.util.Iterator getAttribHandlerIterator()
-
parse
public Cookie[] parse(java.lang.String host, int port, java.lang.String path, boolean secure, Header header) throws MalformedCookieException
Parses the Set-Cookie2 value into an array of Cookies.The syntax for the Set-Cookie2 response header is:
set-cookie = "Set-Cookie2:" cookies cookies = 1#cookie cookie = NAME "=" VALUE * (";" cookie-av) NAME = attr VALUE = value cookie-av = "Comment" "=" value | "CommentURL" "=" <"> http_URL <"> | "Discard" | "Domain" "=" value | "Max-Age" "=" value | "Path" "=" value | "Port" [ "=" <"> portlist <"> ] | "Secure" | "Version" "=" 1*DIGIT portlist = 1#portnum portnum = 1*DIGIT- Specified by:
parsein interfaceCookieSpec- Overrides:
parsein classCookieSpecBase- Parameters:
host- the host from which the Set-Cookie2 value was receivedport- the port from which the Set-Cookie2 value was receivedpath- the path from which the Set-Cookie2 value was receivedsecure- true when the Set-Cookie2 value was received over secure conectionheader- the Set-Cookie2 Header received from the server- Returns:
- an array of Cookies parsed from the Set-Cookie2 value
- Throws:
MalformedCookieException- if an exception occurs during parsing- See Also:
CookieSpec.validate(String, int, String, boolean, Cookie)
-
parse
public Cookie[] parse(java.lang.String host, int port, java.lang.String path, boolean secure, java.lang.String header) throws MalformedCookieException
Description copied from class:CookieSpecBaseParses the Set-Cookie value 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- Specified by:
parsein interfaceCookieSpec- Overrides:
parsein classCookieSpecBase- Parameters:
host- the host from which the Set-Cookie value was receivedport- the port from which the Set-Cookie value was receivedpath- the path from which the Set-Cookie value was receivedsecure- true when the Set-Cookie value was received over secure conectionheader- the Set-Cookie received from the server- Returns:
- an array of Cookies parsed from the Set-Cookie value
- Throws:
MalformedCookieException- if an exception occurs during parsing- See Also:
parse(String, int, String, boolean, org.apache.commons.httpclient.Header)
-
parseAttribute
public void parseAttribute(NameValuePair attribute, Cookie cookie) throws MalformedCookieException
Parse RFC 2965 specific cookie attribute and update the corresponsingCookieproperties.- Specified by:
parseAttributein interfaceCookieSpec- Overrides:
parseAttributein classCookieSpecBase- Parameters:
attribute-NameValuePaircookie attribute from the Set-Cookie2 header.cookie-Cookieto be updated- Throws:
MalformedCookieException- if an exception occurs during parsing
-
validate
public void validate(java.lang.String host, int port, java.lang.String path, boolean secure, Cookie cookie) throws MalformedCookieExceptionPerforms RFC 2965 compliantCookievalidation- Specified by:
validatein interfaceCookieSpec- Overrides:
validatein classCookieSpecBase- Parameters:
host- the host from which theCookiewas receivedport- the port from which theCookiewas receivedpath- the path from which theCookiewas receivedsecure- true when theCookiewas received using a secure connectioncookie- The cookie to validate- Throws:
MalformedCookieException- if an exception occurs during validation
-
match
public boolean match(java.lang.String host, int port, java.lang.String path, boolean secure, Cookie cookie)Return true if the cookie should be submitted with a request with given attributes, false otherwise.- Specified by:
matchin interfaceCookieSpec- Overrides:
matchin classCookieSpecBase- Parameters:
host- the host to which the request is being submittedport- the port to which the request is being submitted (ignored)path- the path to which the request is being submittedsecure- true if the request is using a secure connectioncookie-Cookieto be matched- Returns:
- true if the cookie matches the criterium
-
formatCookie
public java.lang.String formatCookie(Cookie cookie)
Return a string suitable for sending in a "Cookie" header as defined in RFC 2965- Specified by:
formatCookiein interfaceCookieSpec- Overrides:
formatCookiein classCookieSpecBase- Parameters:
cookie- aCookieto be formatted as string- Returns:
- a string suitable for sending in a "Cookie" header.
-
formatCookies
public java.lang.String formatCookies(Cookie[] cookies)
Create a RFC 2965 compliant "Cookie" header value containing allCookies suitable for sending in a "Cookie" header- Specified by:
formatCookiesin interfaceCookieSpec- Overrides:
formatCookiesin classCookieSpecBase- Parameters:
cookies- an array ofCookies to be formatted- Returns:
- a string suitable for sending in a Cookie header.
-
domainMatch
public boolean domainMatch(java.lang.String host, java.lang.String domain)Performs domain-match as defined by the RFC2965.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.)
- Specified by:
domainMatchin interfaceCookieSpec- Overrides:
domainMatchin classCookieSpecBase- Parameters:
host- host name where cookie is received from or being sent to.domain- The cookie domain attribute.- Returns:
- true if the specified host matches the given domain.
-
getVersion
public int getVersion()
- Specified by:
getVersionin interfaceCookieVersionSupport
-
getVersionHeader
public Header getVersionHeader()
- Specified by:
getVersionHeaderin interfaceCookieVersionSupport
-
-