Module io.avaje.jex

Interface Context.Cookie

Enclosing interface:
Context

public static interface Context.Cookie
This interface represents a cookie used in HTTP communication. Cookies are small pieces of data sent from a server to a web browser and stored on the user's computer. They can be used to store information about a user's session, preferences, or other data.
  • Method Details

    • expired

      static Context.Cookie expired(String name)
      Creates and returns a new expired cookie with the given name. This cookie will be sent to the browser but will be immediately discarded. It's useful for removing existing cookies.
      Parameters:
      name - The name of the cookie.
      Returns:
      A new expired cookie with the given name.
    • of

      static Context.Cookie of(String name, String value)
      Creates and returns a new cookie with the given name and value.
      Parameters:
      name - The name of the cookie.
      value - The value to store in the cookie.
      Returns:
      A new cookie with the given name and value.
    • domain

      String domain()
      Returns the domain for which this cookie is valid.
      Returns:
      The domain associated with the cookie, or null if not set.
    • domain

      Context.Cookie domain(String domain)
      Sets the domain for which this cookie is valid.
      Parameters:
      domain - The domain for which the cookie should be valid.
      Returns:
      A new cookie instance with the updated domain.
    • expires

      ZonedDateTime expires()
      Returns the date and time when this cookie expires.
      Returns:
      The expiration date and time of the cookie, or null if not set.
    • expires

      Context.Cookie expires(ZonedDateTime expires)
      Sets the date and time when this cookie expires.
      Parameters:
      expires - The date and time when the cookie should expire.
      Returns:
      A new cookie instance with the updated expires value.
    • httpOnly

      boolean httpOnly()
      Indicates if the HttpOnly attribute is enabled for this cookie.

      The HttpOnly attribute ensures that the cookie is inaccessible to JavaScript, helping to mitigate cross-site scripting (XSS) attacks.

      Returns:
      true if the cookie has the HttpOnly attribute enabled, false otherwise
    • httpOnly

      Context.Cookie httpOnly(boolean httpOnly)
      Sets the HttpOnly attribute for this cookie.

      When enabled, the cookie will not be accessible via client-side scripts, providing additional security against XSS attacks.

      Parameters:
      httpOnly - true to enable the HttpOnly attribute, false to disable it
      Returns:
      this cookie instance with the updated HttpOnly attribute
    • maxAge

      Duration maxAge()
      Returns the maximum age (in seconds) of this cookie. An expired cookie (maxAge of 0) will be deleted immediately by the browser.
      Returns:
      The maximum age of the cookie in seconds, or null if not set.
    • maxAge

      Context.Cookie maxAge(Duration maxAge)
      Sets the maximum age (in seconds) of this cookie. An expired cookie (maxAge of 0) will be deleted immediately by the browser.
      Parameters:
      maxAge - The maximum age of the cookie in seconds.
      Returns:
      A new cookie instance with the updated maxAge.
    • name

      String name()
      Returns the name of this cookie.
      Returns:
      The name of the cookie.
    • partitioned

      boolean partitioned()
      Indicates if the Partitioned attribute is enabled for this cookie.
    • partitioned

      Context.Cookie partitioned(boolean partitioned)
      Set the Partitioned attribute for this cookie.
    • path

      String path()
      Returns the path on the server for which this cookie is valid. Cookies are only sent to the browser if the URL path starts with this value.
      Returns:
      The path associated with the cookie, or null if not set.
    • path

      Context.Cookie path(String path)
      Sets the path on the server for which this cookie is valid. Cookies are only sent to the browser if the URL path starts with this value.
      Parameters:
      path - The path on the server for which the cookie should be valid.
      Returns:
      A new cookie instance with the updated path.
    • sameSite

      Return the SameSite setting.
    • sameSite

      Set the SameSite setting for this cookie.
    • secure

      boolean secure()
      Indicates whether this cookie should only be sent over secure connections (HTTPS).
      Returns:
      True if the cookie should only be sent over secure connections, false otherwise.
    • secure

      Context.Cookie secure(boolean secure)
      Sets the secure attribute for this cookie.

      When enabled, the cookie will only be sent over secure HTTPS connections.

      Parameters:
      secure - true to enable the secure attribute, false to disable it
      Returns:
      this cookie instance with the updated secure attribute
    • toString

      String toString()
      Returns content of the cookie as a 'Set-Cookie:' header value specified by RFC6265.
      Overrides:
      toString in class Object
    • value

      String value()
      Returns the value stored in this cookie.
      Returns:
      The value of the cookie.