org.apache.hc.client5.http.impl.cookie

## Class BasicClientCookie

- java.lang.Object
- - org.apache.hc.client5.http.impl.cookie.BasicClientCookie

- All Implemented Interfaces:
    Serializable, Cloneable, Cookie, SetCookie

      public final class BasicClientCookie
      extends Object
      implements SetCookie, Cloneable, Serializable

  Default implementation of `SetCookie`.
  Since:
    4.0
  See Also:
    Serialized Form

- - ### Field Summary

    - ### Fields inherited from interface org.apache.hc.client5.http.cookie.Cookie

      `DOMAIN_ATTR, EXPIRES_ATTR, HTTP_ONLY_ATTR, MAX_AGE_ATTR, PATH_ATTR, SECURE_ATTR`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `BasicClientCookie(String name, String value)` Default Constructor taking a name and a value.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `Object` | `clone()`
    `boolean` | `containsAttribute(String name)`
    `String` | `getAttribute(String name)`
    `Date` | `getCreationDate()` Deprecated. Use `getCreationInstant()`.
    `Instant` | `getCreationInstant()` Returns creation time of the cookie.
    `String` | `getDomain()` Returns domain attribute of the cookie.
    `Date` | `getExpiryDate()` Deprecated. Use `getExpiryInstant()`
    `Instant` | `getExpiryInstant()` Returns the expiration `Instant` of the cookie, or `null` if none exists.
    `String` | `getName()` Returns the name.
    `String` | `getPath()` Returns the path attribute of the cookie
    `String` | `getValue()` Returns the value.
    `boolean` | `isExpired(Date date)` Deprecated. Use `isExpired(Instant)`
    `boolean` | `isExpired(Instant instant)` Returns true if this cookie has expired.
    `boolean` | `isHttpOnly()` Checks whether this Cookie has been marked as `httpOnly`.
    `boolean` | `isPersistent()` Returns `false` if the cookie should be discarded at the end of the "session"; `true` otherwise.
    `boolean` | `isSecure()` Indicates whether this cookie requires a secure connection.
    `boolean` | `removeAttribute(String name)`
    `void` | `setAttribute(String name, String value)`
    `void` | `setCreationDate(Date creationDate)` Deprecated. Use `setCreationDate(Instant)`
    `void` | `setCreationDate(Instant creationDate)`
    `void` | `setDomain(String domain)` Sets the domain attribute.
    `void` | `setExpiryDate(Date expiryDate)` Deprecated. Use {`setExpiryDate(Instant)`}
    `void` | `setExpiryDate(Instant expiryInstant)` Sets expiration date.
    `void` | `setHttpOnly(boolean httpOnly)` Sets the http-only attribute of the cookie.
    `void` | `setPath(String path)` Sets the path attribute.
    `void` | `setSecure(boolean secure)` Sets the secure attribute of the cookie.
    `void` | `setValue(String value)` Sets the value
    `String` | `toString()`

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

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

- - ### Constructor Detail

    - #### BasicClientCookie

          public BasicClientCookie(String name,
                                   String value)

      Default Constructor taking a name and a value. The value may be null.
      Parameters:
        `name` - The name.
        `value` - The value.

  - ### Method Detail

    - #### getName

          public String getName()

      Returns the name.
      Specified by:
        `getName` in interface `Cookie`
      Returns:
        String name The name

    - #### getValue

          public String getValue()

      Returns the value.
      Specified by:
        `getValue` in interface `Cookie`
      Returns:
        String value The current value.

    - #### setValue

          public void setValue(String value)

      Sets the value
      Specified by:
        `setValue` in interface `SetCookie`
      Parameters:
        `value` -

    - #### getExpiryDate

          @Deprecated
          public Date getExpiryDate()

      Deprecated. Use `getExpiryInstant()`
      Returns the expiration `Date` of the cookie, or `null` if none exists.

      Note: the object returned by this method is considered immutable. Changing it (e.g. using setTime()) could result in undefined behaviour. Do so at your peril.

      Specified by:
        `getExpiryDate` in interface `Cookie`
      Returns:
        Expiration `Date`, or `null`.
      See Also:
        `setExpiryDate(java.util.Date)`

    - #### getExpiryInstant

          public Instant getExpiryInstant()

      Returns the expiration `Instant` of the cookie, or `null` if none exists.

      Note: the object returned by this method is considered immutable. Changing it (e.g. using setTime()) could result in undefined behaviour. Do so at your peril.

      Specified by:
        `getExpiryInstant` in interface `Cookie`
      Returns:
        Expiration `Instant`, or `null`.

    - #### setExpiryDate

          @Deprecated
          public void setExpiryDate(Date expiryDate)

      Deprecated. Use {`setExpiryDate(Instant)`}
      Sets expiration date.

      Note: the object returned by this method is considered immutable. Changing it (e.g. using setTime()) could result in undefined behaviour. Do so at your peril.

      Specified by:
        `setExpiryDate` in interface `SetCookie`
      Parameters:
        `expiryDate` - the `Date` after which this cookie is no longer valid.
      See Also:
        `Cookie.getExpiryDate()`

    - #### setExpiryDate

          public void setExpiryDate(Instant expiryInstant)

      Sets expiration date.

      Note: the object returned by this method is considered immutable. Changing it (e.g. using setTime()) could result in undefined behaviour. Do so at your peril.

      Specified by:
        `setExpiryDate` in interface `SetCookie`
      Parameters:
        `expiryInstant` - the `Instant` after which this cookie is no longer valid.
      Since:
        5.2
      See Also:
        `getExpiryInstant()`

    - #### isPersistent

          public boolean isPersistent()

      Returns `false` if the cookie should be discarded at the end of the "session"; `true` otherwise.
      Specified by:
        `isPersistent` in interface `Cookie`
      Returns:
        `false` if the cookie should be discarded at the end of the "session"; `true` otherwise

    - #### getDomain

          public String getDomain()

      Returns domain attribute of the cookie.
      Specified by:
        `getDomain` in interface `Cookie`
      Returns:
        the value of the domain attribute
      See Also:
        `setDomain(java.lang.String)`

    - #### setDomain

          public void setDomain(String domain)

      Sets the domain attribute.
      Specified by:
        `setDomain` in interface `SetCookie`
      Parameters:
        `domain` - The value of the domain attribute
      See Also:
        `getDomain()`

    - #### getPath

          public String getPath()

      Returns the path attribute of the cookie
      Specified by:
        `getPath` in interface `Cookie`
      Returns:
        The value of the path attribute.
      See Also:
        `setPath(java.lang.String)`

    - #### setPath

          public void setPath(String path)

      Sets the path attribute.
      Specified by:
        `setPath` in interface `SetCookie`
      Parameters:
        `path` - The value of the path attribute
      See Also:
        `getPath()`

    - #### isSecure

          public boolean isSecure()

      Description copied from interface: `Cookie`
      Indicates whether this cookie requires a secure connection.
      Specified by:
        `isSecure` in interface `Cookie`
      Returns:
        `true` if this cookie should only be sent over secure connections.
      See Also:
        `setSecure(boolean)`

    - #### setSecure

          public void setSecure(boolean secure)

      Sets the secure attribute of the cookie.

      When `true` the cookie should only be sent using a secure protocol (https). This should only be set when the cookie's originating server used a secure protocol to set the cookie's value.

      Specified by:
        `setSecure` in interface `SetCookie`
      Parameters:
        `secure` - The value of the secure attribute
      See Also:
        `isSecure()`

    - #### setHttpOnly

          public void setHttpOnly(boolean httpOnly)

      Sets the http-only attribute of the cookie.
      Specified by:
        `setHttpOnly` in interface `SetCookie`
      Parameters:
        `httpOnly` - true if this cookie is to be marked as `httpOnly`, false otherwise
      Since:
        5.2

    - #### isExpired

          @Deprecated
          public boolean isExpired(Date date)

      Deprecated. Use `isExpired(Instant)`
      Returns true if this cookie has expired.
      Specified by:
        `isExpired` in interface `Cookie`
      Parameters:
        `date` - Current time
      Returns:
        `true` if the cookie has expired.

    - #### isExpired

          public boolean isExpired(Instant instant)

      Returns true if this cookie has expired.
      Specified by:
        `isExpired` in interface `Cookie`
      Parameters:
        `instant` - Current time
      Returns:
        `true` if the cookie has expired.

    - #### getCreationDate

          @Deprecated
          public Date getCreationDate()

      Deprecated. Use `getCreationInstant()`.
      Description copied from interface: `Cookie`
      Returns creation time of the cookie.
      Specified by:
        `getCreationDate` in interface `Cookie`
      Since:
        4.4

    - #### getCreationInstant

          public Instant getCreationInstant()

      Description copied from interface: `Cookie`
      Returns creation time of the cookie.
      Specified by:
        `getCreationInstant` in interface `Cookie`
      Since:
        5.2

    - #### isHttpOnly

          public boolean isHttpOnly()

      Description copied from interface: `Cookie`
      Checks whether this Cookie has been marked as `httpOnly`.

      The default implementation returns `false`.

      Specified by:
        `isHttpOnly` in interface `Cookie`
      Returns:
        true if this Cookie has been marked as `httpOnly`, false otherwise
      Since:
        5.2
      See Also:
        `setHttpOnly(boolean)`

    - #### setCreationDate

          @Deprecated
          public void setCreationDate(Date creationDate)

      Deprecated. Use `setCreationDate(Instant)`
      Since:
        4.4

    - #### setCreationDate

          public void setCreationDate(Instant creationDate)

      Since:
        5.2

    - #### setAttribute

          public void setAttribute(String name,
                                   String value)

    - #### getAttribute

          public String getAttribute(String name)

      Specified by:
        `getAttribute` in interface `Cookie`

    - #### containsAttribute

          public boolean containsAttribute(String name)

      Specified by:
        `containsAttribute` in interface `Cookie`

    - #### removeAttribute

          public boolean removeAttribute(String name)

      Since:
        4.4

    - #### clone

          public Object clone()
                       throws CloneNotSupportedException

      Overrides:
        `clone` in class `Object`
      Throws:
        `CloneNotSupportedException`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

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