Class HttpCookie

java.lang.Object
eu.cloudnetservice.driver.network.http.HttpCookie
All Implemented Interfaces:
eu.cloudnetservice.common.Named

public class HttpCookie extends Object implements eu.cloudnetservice.common.Named
Represents a cookie which can be sent by a client to the server using the Cookie header, and vise-vera using the Set-Cookie header. See the mdn documentation about cookies for more details.
Since:
4.0
  • Field Details

    • name

      protected final String name
    • value

      protected final String value
    • domain

      protected final String domain
    • path

      protected final String path
    • httpOnly

      protected final boolean httpOnly
    • secure

      protected final boolean secure
    • wrap

      protected final boolean wrap
    • maxAge

      protected final long maxAge
  • Constructor Details

    • HttpCookie

      public HttpCookie(@NonNull @NonNull String name, @NonNull @NonNull String value)
      Constructs a new http cookie instance. This constructor only takes the required values of a cookie.
      Parameters:
      name - the name of the cookie.
      value - the value of the cookie.
      Throws:
      NullPointerException - if either the given name or value is null.
    • HttpCookie

      public HttpCookie(@NonNull @NonNull String name, @NonNull @NonNull String value, @Nullable @Nullable String domain, @Nullable @Nullable String path, long maxAge)
      Constructs a new http cookie instance.
      Parameters:
      name - the name of the cookie.
      value - the value of the cookie.
      domain - the domain which is allowed to access the cookie. If not set it defaults to the current domain, excluding subdomains.
      path - the path that must request in the request uri in order to include this cookie in the header.
      maxAge - the maximum age until the cookie gets deleted from the client.
      Throws:
      NullPointerException - if either the given name or value is null.
    • HttpCookie

      public HttpCookie(@NonNull @NonNull String name, @NonNull @NonNull String value, @Nullable @Nullable String domain, @Nullable @Nullable String path, boolean httpOnly, boolean secure, boolean wrap, long maxAge)
      Constructs a new http cookie instance.
      Parameters:
      name - the name of the cookie.
      value - the value of the cookie.
      domain - the domain which is allowed to access the cookie. If not set it defaults to the current domain, excluding subdomains.
      path - the path that must request in the request uri in order to include this cookie in the header.
      httpOnly - sets that the cookie is invisible to scripts and will only be sent in http requests to the server.
      secure - sets that the cookie is only sent to the server when the connection is encrypted (using https).
      wrap - sets if the value of this cookie should be wrapped in double quotes.
      maxAge - the maximum age until the cookie gets deleted from the client.
      Throws:
      NullPointerException - if either the given name or value is null.
  • Method Details

    • name

      @NonNull public @NonNull String name()
      Get the name of this cookie.
      Specified by:
      name in interface eu.cloudnetservice.common.Named
      Returns:
      the name of this cookie.
    • value

      @NonNull public @NonNull String value()
      Get the value of this cookie.
      Returns:
      the value of this cookie.
    • domain

      @Nullable public @Nullable String domain()
      Get the domain which is allowed to receive the cookie. If not set only the current domain is allowed to receive the cookie, excluding subdomains. If set to the current domain then subdomains are always included.
      Returns:
      the domain which is allowed to receive the cookie.
    • path

      @Nullable public @Nullable String path()
      Get the path which must be present in the request uri to send the cookie to the server. For example, if the path is set to /docs then the following uris would receive the cookie:
      1. /docs
      2. /docs/
      3. /docs/getting-started
      while these would not receive the cookie:
      1. /
      2. /helpdesk
      3. /documentation/getting-started
      Returns:
      the path which must be present in the request uri to send the cookie to the server.
    • maxAge

      public long maxAge()
      Get the max age this cookie persists on the client side until it gets emitted.
      Returns:
      the max age of this cookie.
    • httpOnly

      public boolean httpOnly()
      Get if the cookie is only visible to http request, blocking access to the cookie from e.g. scripts running in the browser.
      Returns:
      if the cookie is only visible to http request.
    • secure

      public boolean secure()
      Get if this cookie should only get transferred to the server if the server connection is encrypted (using https). The only point when it is transmitted to the server even when using http is to localhost.
      Returns:
      if this cookie should only get transferred to the server if the server connection is encrypted.
    • wrap

      public boolean wrap()
      Get if the value of this cookie is wrapped in double quotes. This is an en-/de- coder only option which is not visible on the client side.
      Returns:
      if the value of this cookie is wrapped in double quotes