Class HttpCookieUtils

java.lang.Object
org.eclipse.jetty.server.HttpCookieUtils

public final class HttpCookieUtils extends Object

Utility methods for server-side HTTP cookie handling.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    A HttpField that holds an HttpHeader.SET_COOKIE as a HttpCookie instance, delaying any value generation until HttpCookieUtils.SetCookieHttpField.getValue() is called.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Name of context attribute with default SameSite cookie value
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.eclipse.jetty.http.HttpCookie
    checkSameSite(org.eclipse.jetty.http.HttpCookie cookie, org.eclipse.jetty.util.Attributes attributes)
    Check that samesite is set on the cookie.
    static String
    getRFC2965SetCookie(org.eclipse.jetty.http.HttpCookie httpCookie)
     
    static String
    getRFC6265SetCookie(org.eclipse.jetty.http.HttpCookie httpCookie)
     
    static org.eclipse.jetty.http.HttpCookie.SameSite
    getSameSiteDefault(org.eclipse.jetty.util.Attributes contextAttributes)
    Get the default value for SameSite cookie attribute, if one has been set for the given context.
    static String
    getSetCookie(org.eclipse.jetty.http.HttpCookie httpCookie, org.eclipse.jetty.http.CookieCompliance compliance)
     
    static boolean
    match(String setCookieHeader, String name, String domain, String path)
    Check if the Set-Cookie header represented as a string is for the name, domain and path given.
    static boolean
    match(org.eclipse.jetty.http.HttpCookie cookie, String name, String domain, String path)
    Check if the HttpCookie is for the given name, domain and path.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SAME_SITE_DEFAULT_ATTRIBUTE

      public static final String SAME_SITE_DEFAULT_ATTRIBUTE
      Name of context attribute with default SameSite cookie value
      See Also:
  • Method Details

    • checkSameSite

      public static org.eclipse.jetty.http.HttpCookie checkSameSite(org.eclipse.jetty.http.HttpCookie cookie, org.eclipse.jetty.util.Attributes attributes)
      Check that samesite is set on the cookie. If not, use a context default value, if one has been set.
      Parameters:
      cookie - the cookie to check
      attributes - the context to check settings
      Returns:
      either the original cookie, or a new one that has the samesit default set
    • getSameSiteDefault

      public static org.eclipse.jetty.http.HttpCookie.SameSite getSameSiteDefault(org.eclipse.jetty.util.Attributes contextAttributes)
      Get the default value for SameSite cookie attribute, if one has been set for the given context.
      Parameters:
      contextAttributes - the context to check for default SameSite value
      Returns:
      the default SameSite value or null if one does not exist
      Throws:
      IllegalStateException - if the default value is not a permitted value
    • getSetCookie

      public static String getSetCookie(org.eclipse.jetty.http.HttpCookie httpCookie, org.eclipse.jetty.http.CookieCompliance compliance)
    • getRFC2965SetCookie

      public static String getRFC2965SetCookie(org.eclipse.jetty.http.HttpCookie httpCookie)
    • getRFC6265SetCookie

      public static String getRFC6265SetCookie(org.eclipse.jetty.http.HttpCookie httpCookie)
    • match

      public static boolean match(String setCookieHeader, String name, String domain, String path)
      Check if the Set-Cookie header represented as a string is for the name, domain and path given.
      Parameters:
      setCookieHeader - a Set-Cookie header
      name - the cookie name to check
      domain - the cookie domain to check
      path - the cookie path to check
      Returns:
      true if all of the name, domain and path match the Set-Cookie header, false otherwise
    • match

      public static boolean match(org.eclipse.jetty.http.HttpCookie cookie, String name, String domain, String path)
      Check if the HttpCookie is for the given name, domain and path.
      Parameters:
      cookie - the jetty HttpCookie to check
      name - the cookie name to check
      domain - the cookie domain to check
      path - the cookie path to check
      Returns:
      true if name, domain, and path, match all match the HttpCookie, false otherwise