Class Cookie.Builder

java.lang.Object
com.teamdev.jxbrowser.cookie.Cookie.Builder
Enclosing interface:
Cookie

public static final class Cookie.Builder extends Object
A builder of Cookie.

Builders are created by invoking Cookie.newBuilder(String). Each of the setter methods modifies the state of the builder and returns the same instance. Builders are not thread-safe and should not be used concurrently from multiple threads without external synchronization.

  • Method Details

    • name

      public Cookie.Builder name(String name)
      Sets the cookie name.
      Parameters:
      name - the cookie name
      Returns:
      this builder
    • value

      public Cookie.Builder value(String value)
      Sets the cookie value.
      Parameters:
      value - the cookie value
      Returns:
      this builder
    • path

      public Cookie.Builder path(String path)
      Sets the cookie path. For example, "/".
      Parameters:
      path - the cookie path
      Returns:
      this builder
    • secure

      public Cookie.Builder secure(boolean secure)
      Specifies whether the cookie is restricted to a secure protocol (HTTPS or WSS) or it can be sent using any protocol.
      Parameters:
      secure - the flag value
      Returns:
      this builder
    • httpOnly

      public Cookie.Builder httpOnly(boolean httpOnly)
      Specifies whether the cookie is considered HTTP only.
      Parameters:
      httpOnly - the flag value
      Returns:
      this builder
    • creationTime

      public Cookie.Builder creationTime(Timestamp creationTime)
      Sets the cookie creation time. If not specified, the current time will be assigned for the created cookie.
      Parameters:
      creationTime - the cookie creation time
      Returns:
      this builder
    • expirationTime

      public Cookie.Builder expirationTime(Timestamp expirationTime)
      Sets the cookie expiration time. If not specified, the cookie is treated as a session cookie.
      Parameters:
      expirationTime - the cookie expiration time
      Returns:
      this builder
    • sameSite

      public Cookie.Builder sameSite(SameSite sameSite)
      Sets the SameSite cookie attribute value that allows you to declare if your cookie should be restricted to a first-party or same-site context.

      By default, the attribute value is set to SameSite.LAX_MODE which means cookies are only set when the domain in the URL of the browser matches the domain of the cookie — a first-party cookie.

      The SameSite.NONE value requires that the secure(boolean) attribute is set to true.

      Parameters:
      sameSite - the SameSite cookie attribute value
      Returns:
      this builder
    • build

      public Cookie build()
      Returns a new Cookie built from the current state of this builder.
      Returns:
      a new Cookie instance