CookieSpecBase (HttpClient Library (Version 3.1))
Date: 2016-03-09

org.apache.commons.httpclient.cookie

## Class CookieSpecBase

- java.lang.Object
- - org.apache.commons.httpclient.cookie.CookieSpecBase

- All Implemented Interfaces:
    CookieSpec
  Direct Known Subclasses:
    NetscapeDraftSpec, RFC2109Spec, RFC2965Spec

      public class CookieSpecBase
      extends java.lang.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

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static Log` | `LOG` Log object

    - ### Fields inherited from interface org.apache.commons.httpclient.cookie.CookieSpec

      `PATH_DELIM, PATH_DELIM_CHAR`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CookieSpecBase()` Default constructor

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `domainMatch(java.lang.String host, java.lang.String domain)` Performs domain-match as implemented in common browsers.
    `java.lang.String` | `formatCookie(Cookie cookie)` Return a string suitable for sending in a `"Cookie"` header
    `Header` | `formatCookieHeader(Cookie cookie)` Create a `"Cookie"` `Header` containing the `Cookie`.
    `Header` | `formatCookieHeader(Cookie[] cookies)` Create a `"Cookie"` `Header` containing all `Cookie`s in cookies.
    `java.lang.String` | `formatCookies(Cookie[] cookies)` Create a `"Cookie"` header value containing all `Cookie`s in cookies suitable for sending in a `"Cookie"` header
    `java.util.Collection` | `getValidDateFormats()` Returns the `Collection` of date patterns used for parsing.
    `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.
    `Cookie[]` | `match(java.lang.String host, int port, java.lang.String path, boolean secure, Cookie[] cookies)` Return an array of `Cookie`s that 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, Header header)` Parse the `"Set-Cookie"` `Header` into an array of `Cookie`s.
    `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 `Cookie`s.
    `void` | `parseAttribute(NameValuePair attribute, Cookie cookie)` Parse the cookie attribute and update the corresponsing `Cookie` properties.
    `boolean` | `pathMatch(java.lang.String path, java.lang.String topmostPath)` Performs path-match as implemented in common browsers.
    `void` | `setValidDateFormats(java.util.Collection datepatterns)` Sets the `Collection` of date patterns used for parsing.
    `void` | `validate(java.lang.String host, int port, java.lang.String path, boolean secure, Cookie cookie)` Performs most common `Cookie` validation

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### LOG

          protected static final Log LOG

      Log object

  - ### Constructor Detail

    - #### CookieSpecBase

          public CookieSpecBase()

      Default constructor

  - ### Method Detail

    - #### parse

          public Cookie[] parse(java.lang.String host,
                       int port,
                       java.lang.String path,
                       boolean secure,
                       java.lang.String header)
                         throws MalformedCookieException

      Parses the Set-Cookie value into an array of `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

      Specified by:
        `parse` in interface `CookieSpec`
      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 `Cookie`s parsed from the Set-Cookie 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,
                       Header header)
                         throws MalformedCookieException

      Parse the `"Set-Cookie"` `Header` into an array of `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

      Specified by:
        `parse` in interface `CookieSpec`
      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 `Cookie`s parsed from the `"Set-Cookie"` header
      Throws:
        `MalformedCookieException` - if an exception occurs during parsing
      See Also:
        `CookieSpec.validate(String, int, String, boolean, Cookie)`

    - #### parseAttribute

          public void parseAttribute(NameValuePair attribute,
                            Cookie cookie)
                              throws MalformedCookieException

      Parse the cookie attribute and update the corresponsing `Cookie` properties.
      Specified by:
        `parseAttribute` in interface `CookieSpec`
      Parameters:
        `attribute` - `HeaderElement` cookie attribute from the `Set- Cookie`
        `cookie` - `Cookie` to be updated
      Throws:
        `MalformedCookieException` - if an exception occurs during parsing

    - #### getValidDateFormats

          public java.util.Collection getValidDateFormats()

      Description copied from interface: `CookieSpec`
      Returns the `Collection` of date patterns used for parsing. The String patterns are compatible with the `SimpleDateFormat`.
      Specified by:
        `getValidDateFormats` in interface `CookieSpec`
      Returns:
        collection of date patterns

    - #### setValidDateFormats

          public void setValidDateFormats(java.util.Collection datepatterns)

      Description copied from interface: `CookieSpec`
      Sets the `Collection` of date patterns used for parsing. The String patterns must be compatible with `SimpleDateFormat`.
      Specified by:
        `setValidDateFormats` in interface `CookieSpec`
      Parameters:
        `datepatterns` - collection of date patterns

    - #### validate

          public void validate(java.lang.String host,
                      int port,
                      java.lang.String path,
                      boolean secure,
                      Cookie cookie)
                        throws MalformedCookieException

      Performs most common `Cookie` validation
      Specified by:
        `validate` in interface `CookieSpec`
      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

    - #### 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:
        `match` in interface `CookieSpec`
      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` - `Cookie` to be matched
      Returns:
        true if the cookie matches the criterium

    - #### domainMatch

          public boolean domainMatch(java.lang.String host,
                            java.lang.String domain)

      Performs domain-match as implemented in common browsers.
      Specified by:
        `domainMatch` in interface `CookieSpec`
      Parameters:
        `host` - The target host.
        `domain` - The cookie domain attribute.
      Returns:
        true if the specified host matches the given domain.

    - #### pathMatch

          public boolean pathMatch(java.lang.String path,
                          java.lang.String topmostPath)

      Performs path-match as implemented in common browsers.
      Specified by:
        `pathMatch` in interface `CookieSpec`
      Parameters:
        `path` - The target path.
        `topmostPath` - The cookie path attribute.
      Returns:
        true if the paths match

    - #### match

          public Cookie[] match(java.lang.String host,
                       int port,
                       java.lang.String path,
                       boolean secure,
                       Cookie[] cookies)

      Return an array of `Cookie`s that should be submitted with a request with given attributes, `false` otherwise.
      Specified by:
        `match` in interface `CookieSpec`
      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 `Cookie`s to be matched
      Returns:
        an array of `Cookie`s matching the criterium

    - #### formatCookie

          public java.lang.String formatCookie(Cookie cookie)

      Return a string suitable for sending in a `"Cookie"` header
      Specified by:
        `formatCookie` in interface `CookieSpec`
      Parameters:
        `cookie` - a `Cookie` to be formatted as string
      Returns:
        a string suitable for sending in a `"Cookie"` header.

    - #### formatCookies

          public java.lang.String formatCookies(Cookie[] cookies)
                                         throws java.lang.IllegalArgumentException

      Create a `"Cookie"` header value containing all `Cookie`s in cookies suitable for sending in a `"Cookie"` header
      Specified by:
        `formatCookies` in interface `CookieSpec`
      Parameters:
        `cookies` - an array of `Cookie`s to be formatted
      Returns:
        a string suitable for sending in a Cookie header.
      Throws:
        `java.lang.IllegalArgumentException` - if an input parameter is illegal

    - #### formatCookieHeader

          public Header formatCookieHeader(Cookie[] cookies)

      Create a `"Cookie"` `Header` containing all `Cookie`s in cookies.
      Specified by:
        `formatCookieHeader` in interface `CookieSpec`
      Parameters:
        `cookies` - an array of `Cookie`s to be formatted as a `" Cookie"` header
      Returns:
        a `"Cookie"` `Header`.

    - #### formatCookieHeader

          public Header formatCookieHeader(Cookie cookie)

      Create a `"Cookie"` `Header` containing the `Cookie`.
      Specified by:
        `formatCookieHeader` in interface `CookieSpec`
      Parameters:
        `cookie` - `Cookie`s to be formatted as a `Cookie` header
      Returns:
        a Cookie header.

Copyright (c) 1999-2005 - Apache Software Foundation