Class HttpCookie

java.lang.Object
org.eclipse.jetty.http.HttpCookie

public class HttpCookie extends Object
  • Field Details

    • LOG

      private static final Logger LOG
    • HTTP_ONLY_COMMENT

      public static final String HTTP_ONLY_COMMENT
      If this string is found within the comment parsed with isHttpOnlyInComment(String) the check will return true
      See Also:
    • SAME_SITE_COMMENT

      private static final String SAME_SITE_COMMENT
      These strings are used by getSameSiteFromComment(String) to check for a SameSite specifier in the comment
      See Also:
    • SAME_SITE_NONE_COMMENT

      public static final String SAME_SITE_NONE_COMMENT
      See Also:
    • SAME_SITE_LAX_COMMENT

      public static final String SAME_SITE_LAX_COMMENT
      See Also:
    • SAME_SITE_STRICT_COMMENT

      public static final String SAME_SITE_STRICT_COMMENT
      See Also:
    • SAME_SITE_DEFAULT_ATTRIBUTE

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

      private final String _name
    • _value

      private final String _value
    • _comment

      private final String _comment
    • _domain

      private final String _domain
    • _maxAge

      private final long _maxAge
    • _path

      private final String _path
    • _secure

      private final boolean _secure
    • _version

      private final int _version
    • _httpOnly

      private final boolean _httpOnly
    • _expiration

      private final long _expiration
    • _sameSite

      private final HttpCookie.SameSite _sameSite
  • Constructor Details

  • Method Details

    • getName

      public String getName()
      Returns:
      the cookie name
    • getValue

      public String getValue()
      Returns:
      the cookie value
    • getComment

      public String getComment()
      Returns:
      the cookie comment
    • getDomain

      public String getDomain()
      Returns:
      the cookie domain
    • getMaxAge

      public long getMaxAge()
      Returns:
      the cookie max age in seconds
    • getPath

      public String getPath()
      Returns:
      the cookie path
    • isSecure

      public boolean isSecure()
      Returns:
      whether the cookie is valid for secure domains
    • getVersion

      public int getVersion()
      Returns:
      the cookie version
    • getSameSite

      public HttpCookie.SameSite getSameSite()
      Returns:
      the cookie SameSite enum attribute
    • isHttpOnly

      public boolean isHttpOnly()
      Returns:
      whether the cookie is valid for the http protocol only
    • isExpired

      public boolean isExpired(long timeNanos)
      Parameters:
      timeNanos - the time to check for cookie expiration, in nanoseconds
      Returns:
      whether the cookie is expired by the given time
    • asString

      public String asString()
      Returns:
      a string representation of this cookie
    • quoteOnlyOrAppend

      private static void quoteOnlyOrAppend(StringBuilder buf, String s, boolean quote)
    • isQuoteNeededForCookie

      private static boolean isQuoteNeededForCookie(String s)
      Does a cookie value need to be quoted?
      Parameters:
      s - value string
      Returns:
      true if quoted;
      Throws:
      IllegalArgumentException - If there a control characters in the string
    • getSetCookie

      public String getSetCookie(CookieCompliance compliance)
    • getRFC2965SetCookie

      public String getRFC2965SetCookie()
    • getRFC6265SetCookie

      public String getRFC6265SetCookie()
    • isHttpOnlyInComment

      public static boolean isHttpOnlyInComment(String comment)
    • getSameSiteFromComment

      public static HttpCookie.SameSite getSameSiteFromComment(String comment)
    • getSameSiteDefault

      public static HttpCookie.SameSite getSameSiteDefault(javax.servlet.ServletContext context)
      Get the default value for SameSite cookie attribute, if one has been set for the given context.
      Parameters:
      context - 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
    • getCommentWithoutAttributes

      public static String getCommentWithoutAttributes(String comment)
    • getCommentWithAttributes

      public static String getCommentWithAttributes(String comment, boolean httpOnly, HttpCookie.SameSite sameSite)