org.apache.commons.httpclient.cookie

Class RFC2965Spec

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
static StringSET_COOKIE2_KEY
Cookie Response Header name for cookies processed by this spec.
Constructor Summary
RFC2965Spec()
Default constructor
Method Summary
booleandomainMatch(String host, String domain)
Performs domain-match as defined by the RFC2965.
protected CookieAttributeHandlerfindAttribHandler(String name)
Finds an attribute handler CookieAttributeHandler for the given attribute.
StringformatCookie(Cookie cookie)
Return a string suitable for sending in a "Cookie" header as defined in RFC 2965
StringformatCookies(Cookie[] cookies)
Create a RFC 2965 compliant "Cookie" header value containing all Cookies suitable for sending in a "Cookie" header
protected CookieAttributeHandlergetAttribHandler(String name)
Gets attribute handler CookieAttributeHandler for the given attribute.
protected IteratorgetAttribHandlerIterator()
intgetVersion()
HeadergetVersionHeader()
booleanmatch(String host, int port, String path, boolean secure, Cookie cookie)
Return true if the cookie should be submitted with a request with given attributes, false otherwise.
Cookie[]parse(String host, int port, String path, boolean secure, Header header)
Parses the Set-Cookie2 value into an array of Cookies.
Cookie[]parse(String host, int port, String path, boolean secure, String header)
voidparseAttribute(NameValuePair attribute, Cookie cookie)
Parse RFC 2965 specific cookie attribute and update the corresponsing Cookie properties.
protected voidregisterAttribHandler(String name, CookieAttributeHandler handler)
voidvalidate(String host, int port, String path, boolean secure, Cookie cookie)
Performs RFC 2965 compliant Cookie validation

Field Detail

SET_COOKIE2_KEY

public static final String SET_COOKIE2_KEY
Cookie Response Header name for cookies processed by this spec.

Constructor Detail

RFC2965Spec

public RFC2965Spec()
Default constructor

Method Detail

domainMatch

public boolean domainMatch(String host, String domain)
Performs domain-match as defined by the RFC2965.

Host A's name domain-matches host B's if

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.

findAttribHandler

protected CookieAttributeHandler findAttribHandler(String name)
Finds an attribute handler CookieAttributeHandler for 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

formatCookie

public String formatCookie(Cookie cookie)
Return a string suitable for sending in a "Cookie" header as defined in RFC 2965

Parameters: cookie a Cookie to be formatted as string

Returns: a string suitable for sending in a "Cookie" header.

formatCookies

public String formatCookies(Cookie[] cookies)
Create a RFC 2965 compliant "Cookie" header value containing all Cookies suitable for sending in a "Cookie" header

Parameters: cookies an array of Cookies to be formatted

Returns: a string suitable for sending in a Cookie header.

getAttribHandler

protected CookieAttributeHandler getAttribHandler(String name)
Gets attribute handler CookieAttributeHandler for the given attribute.

Parameters: name attribute name. e.g. Domain, Path, etc.

Throws: IllegalStateException if handler not found for the specified attribute.

getAttribHandlerIterator

protected Iterator getAttribHandlerIterator()

getVersion

public int getVersion()

getVersionHeader

public Header getVersionHeader()

match

public boolean match(String host, int port, String path, boolean secure, Cookie cookie)
Return true if the cookie should be submitted with a request with given attributes, false otherwise.

Parameters: host the host to which the request is being submitted port the port to which the request is being submitted (ignored) path the path to which the request is being submitted secure true if the request is using a secure connection

Returns: true if the cookie matches the criterium

parse

public Cookie[] parse(String host, int port, String path, boolean secure, Header header)
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
 

Parameters: host the host from which the Set-Cookie2 value was received port the port from which the Set-Cookie2 value was received path the path from which the Set-Cookie2 value was received secure true when the Set-Cookie2 value was received over secure conection header 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

parse

public Cookie[] parse(String host, int port, String path, boolean secure, String header)

See Also: RFC2965Spec

parseAttribute

public void parseAttribute(NameValuePair attribute, Cookie cookie)
Parse RFC 2965 specific cookie attribute and update the corresponsing Cookie properties.

Parameters: attribute NameValuePair cookie attribute from the Set-Cookie2 header. cookie Cookie to be updated

Throws: MalformedCookieException if an exception occurs during parsing

registerAttribHandler

protected void registerAttribHandler(String name, CookieAttributeHandler handler)

validate

public void validate(String host, int port, String path, boolean secure, Cookie cookie)
Performs RFC 2965 compliant Cookie validation

Parameters: host the host from which the Cookie was received port the port from which the Cookie was received path the path from which the Cookie was received secure true when the Cookie was received using a secure connection cookie The cookie to validate

Throws: MalformedCookieException if an exception occurs during validation

Copyright (c) 1999-2005 - Apache Software Foundation