org.apache.http.impl.cookie

## Class DefaultCookieSpec

- java.lang.Object
- - org.apache.http.impl.cookie.DefaultCookieSpec

- All Implemented Interfaces:
    CookieSpec
  Direct Known Subclasses:
    BestMatchSpec

      @Contract(threading=SAFE)
      public class DefaultCookieSpec
      extends Object
      implements CookieSpec

  Default cookie specification that picks up the best matching cookie policy based on the format of cookies sent with the HTTP response.
  Since:
    4.4

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultCookieSpec()`
    `DefaultCookieSpec(String[] datepatterns, boolean oneHeader)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `List<org.apache.http.Header>` | `formatCookies(List<Cookie> cookies)` Create `"Cookie"` headers for an array of Cookies.
    `int` | `getVersion()` Returns version of the state management this cookie specification conforms to.
    `org.apache.http.Header` | `getVersionHeader()` Returns a request header identifying what version of the state management specification is understood.
    `boolean` | `match(Cookie cookie, CookieOrigin origin)` Determines if a Cookie matches the target location.
    `List<Cookie>` | `parse(org.apache.http.Header header, CookieOrigin origin)` Parse the `"Set-Cookie"` Header into an array of Cookies.
    `String` | `toString()`
    `void` | `validate(Cookie cookie, CookieOrigin origin)` Validate the cookie according to validation rules defined by the cookie specification.

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

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

- - ### Constructor Detail

    - #### DefaultCookieSpec

          public DefaultCookieSpec(String[] datepatterns,
                           boolean oneHeader)

    - #### DefaultCookieSpec

          public DefaultCookieSpec()

  - ### Method Detail

    - #### parse

          public List<Cookie> parse(org.apache.http.Header header,
                           CookieOrigin origin)
                             throws MalformedCookieException

      Description copied from interface: `CookieSpec`
      Parse the `"Set-Cookie"` Header into an array of Cookies.

      This method will not perform the validation of the resultant `Cookie`s

      Specified by:
        `parse` in interface `CookieSpec`
      Parameters:
        `header` - the `Set-Cookie` received from the server
        `origin` - details of the cookie origin
      Returns:
        an array of `Cookie`s parsed from the header
      Throws:
        `MalformedCookieException` - if an exception occurs during parsing
      See Also:
        `CookieSpec.validate(org.apache.http.cookie.Cookie, org.apache.http.cookie.CookieOrigin)`

    - #### validate

          public void validate(Cookie cookie,
                      CookieOrigin origin)
                        throws MalformedCookieException

      Description copied from interface: `CookieSpec`
      Validate the cookie according to validation rules defined by the cookie specification.
      Specified by:
        `validate` in interface `CookieSpec`
      Parameters:
        `cookie` - the Cookie to validate
        `origin` - details of the cookie origin
      Throws:
        `MalformedCookieException` - if the cookie is invalid

    - #### match

          public boolean match(Cookie cookie,
                      CookieOrigin origin)

      Description copied from interface: `CookieSpec`
      Determines if a Cookie matches the target location.
      Specified by:
        `match` in interface `CookieSpec`
      Parameters:
        `cookie` - the Cookie to be matched
        `origin` - the target to test against
      Returns:
        `true` if the cookie should be submitted with a request with given attributes, `false` otherwise.

    - #### formatCookies

          public List<org.apache.http.Header> formatCookies(List<Cookie> cookies)

      Description copied from interface: `CookieSpec`
      Create `"Cookie"` headers for an array of Cookies.
      Specified by:
        `formatCookies` in interface `CookieSpec`
      Parameters:
        `cookies` - the Cookies format into a Cookie header
      Returns:
        a Header for the given Cookies.

    - #### getVersion

          public int getVersion()

      Description copied from interface: `CookieSpec`
      Returns version of the state management this cookie specification conforms to.
      Specified by:
        `getVersion` in interface `CookieSpec`
      Returns:
        version of the state management specification

    - #### getVersionHeader

          public org.apache.http.Header getVersionHeader()

      Description copied from interface: `CookieSpec`
      Returns a request header identifying what version of the state management specification is understood. May be `null` if the cookie specification does not support `Cookie2` header.
      Specified by:
        `getVersionHeader` in interface `CookieSpec`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 1999–2022 The Apache Software Foundation. All rights reserved.