org.apache.commons.httpclient.cookie

Class CookieSpecBase

public class CookieSpecBase extends Object implements CookieSpec

Cookie management functions shared by all specification.

Since: 2.0

Author: B.C. Holmes Park, Sung-Gu Doug Sale Rod Waldhoff dIon Gillard Sean C. Sullivan John Evans Marc A. Saegesser Oleg Kalnichevski Mike Bowler

Field Summary
protected static LogLOG
Log object
Constructor Summary
CookieSpecBase()
Default constructor
Method Summary
booleandomainMatch(String host, String domain)
Performs domain-match as implemented in common browsers.
StringformatCookie(Cookie cookie)
Return a string suitable for sending in a "Cookie" header
HeaderformatCookieHeader(Cookie[] cookies)
Create a "Cookie" {@link Header} containing all {@link Cookie}s in cookies.
HeaderformatCookieHeader(Cookie cookie)
Create a "Cookie" {@link Header} containing the {@link Cookie}.
StringformatCookies(Cookie[] cookies)
Create a "Cookie" header value containing all {@link Cookie}s in cookies suitable for sending in a "Cookie" header
CollectiongetValidDateFormats()
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[]match(String host, int port, String path, boolean secure, Cookie[] cookies)
Return an array of {@link Cookie}s that should be submitted with a request with given attributes, false otherwise.
Cookie[]parse(String host, int port, String path, boolean secure, String header)
Parses the Set-Cookie value into an array of Cookies.
Cookie[]parse(String host, int port, String path, boolean secure, Header header)
Parse the "Set-Cookie" {@link Header} into an array of {@link Cookie}s.
voidparseAttribute(NameValuePair attribute, Cookie cookie)
Parse the cookie attribute and update the corresponsing {@link Cookie} properties.
booleanpathMatch(String path, String topmostPath)
Performs path-match as implemented in common browsers.
voidsetValidDateFormats(Collection datepatterns)
voidvalidate(String host, int port, String path, boolean secure, Cookie cookie)
Performs most common {@link Cookie} validation

Field Detail

LOG

protected static final Log LOG
Log object

Constructor Detail

CookieSpecBase

public CookieSpecBase()
Default constructor

Method Detail

domainMatch

public boolean domainMatch(String host, String domain)
Performs domain-match as implemented in common browsers.

Parameters: host The target host. domain The cookie domain attribute.

Returns: true if the specified host matches the given domain.

formatCookie

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

Parameters: cookie a {@link Cookie} to be formatted as string

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

formatCookieHeader

public Header formatCookieHeader(Cookie[] cookies)
Create a "Cookie" {@link Header} containing all {@link Cookie}s in cookies.

Parameters: cookies an array of {@link Cookie}s to be formatted as a " Cookie" header

Returns: a "Cookie" {@link Header}.

formatCookieHeader

public Header formatCookieHeader(Cookie cookie)
Create a "Cookie" {@link Header} containing the {@link Cookie}.

Parameters: cookie Cookies to be formatted as a Cookie header

Returns: a Cookie header.

formatCookies

public String formatCookies(Cookie[] cookies)
Create a "Cookie" header value containing all {@link Cookie}s in cookies suitable for sending in a "Cookie" header

Parameters: cookies an array of {@link Cookie}s to be formatted

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

Throws: IllegalArgumentException if an input parameter is illegal

getValidDateFormats

public Collection getValidDateFormats()

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 cookie {@link Cookie} to be matched

Returns: true if the cookie matches the criterium

match

public Cookie[] match(String host, int port, String path, boolean secure, Cookie[] cookies)
Return an array of {@link Cookie}s that 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 (currently ignored) path the path to which the request is being submitted secure true if the request is using a secure protocol cookies an array of Cookies to be matched

Returns: an array of Cookies matching the criterium

parse

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

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

parse

public Cookie[] parse(String host, int port, String path, boolean secure, Header header)
Parse the "Set-Cookie" {@link Header} into an array of {@link Cookie}s.

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
 

Parameters: host the host from which the Set-Cookie header was received port the port from which the Set-Cookie header was received path the path from which the Set-Cookie header was received secure true when the Set-Cookie header was received over secure conection header the Set-Cookie received from the server

Returns: an array of Cookies parsed from the "Set-Cookie" header

Throws: MalformedCookieException if an exception occurs during parsing

parseAttribute

public void parseAttribute(NameValuePair attribute, Cookie cookie)
Parse the cookie attribute and update the corresponsing {@link Cookie} properties.

Parameters: attribute {@link HeaderElement} cookie attribute from the Set- Cookie cookie {@link Cookie} to be updated

Throws: MalformedCookieException if an exception occurs during parsing

pathMatch

public boolean pathMatch(String path, String topmostPath)
Performs path-match as implemented in common browsers.

Parameters: path The target path. topmostPath The cookie path attribute.

Returns: true if the paths match

setValidDateFormats

public void setValidDateFormats(Collection datepatterns)

validate

public void validate(String host, int port, String path, boolean secure, Cookie cookie)
Performs most common {@link Cookie} validation

Parameters: host the host from which the {@link Cookie} was received port the port from which the {@link Cookie} was received path the path from which the {@link Cookie} was received secure true when the {@link 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