Class HttpCookie


  • public class HttpCookie
    extends java.lang.Object
    • Field Detail

      • LOG

        private static final Logger LOG
      • __01Jan1970_COOKIE

        private static final java.lang.String __01Jan1970_COOKIE
      • SAME_SITE_NONE_COMMENT

        public static final java.lang.String SAME_SITE_NONE_COMMENT
        See Also:
        Constant Field Values
      • SAME_SITE_LAX_COMMENT

        public static final java.lang.String SAME_SITE_LAX_COMMENT
        See Also:
        Constant Field Values
      • SAME_SITE_STRICT_COMMENT

        public static final java.lang.String SAME_SITE_STRICT_COMMENT
        See Also:
        Constant Field Values
      • SAME_SITE_DEFAULT_ATTRIBUTE

        public static final java.lang.String SAME_SITE_DEFAULT_ATTRIBUTE
        Name of context attribute with default SameSite cookie value
        See Also:
        Constant Field Values
      • _name

        private final java.lang.String _name
      • _value

        private final java.lang.String _value
      • _comment

        private final java.lang.String _comment
      • _domain

        private final java.lang.String _domain
      • _maxAge

        private final long _maxAge
      • _path

        private final java.lang.String _path
      • _secure

        private final boolean _secure
      • _version

        private final int _version
      • _httpOnly

        private final boolean _httpOnly
      • _expiration

        private final long _expiration
    • Constructor Detail

      • HttpCookie

        public HttpCookie​(java.lang.String name,
                          java.lang.String value)
      • HttpCookie

        public HttpCookie​(java.lang.String name,
                          java.lang.String value,
                          java.lang.String domain,
                          java.lang.String path)
      • HttpCookie

        public HttpCookie​(java.lang.String name,
                          java.lang.String value,
                          long maxAge)
      • HttpCookie

        public HttpCookie​(java.lang.String name,
                          java.lang.String value,
                          java.lang.String domain,
                          java.lang.String path,
                          long maxAge,
                          boolean httpOnly,
                          boolean secure)
      • HttpCookie

        public HttpCookie​(java.lang.String name,
                          java.lang.String value,
                          java.lang.String domain,
                          java.lang.String path,
                          long maxAge,
                          boolean httpOnly,
                          boolean secure,
                          java.lang.String comment,
                          int version)
      • HttpCookie

        public HttpCookie​(java.lang.String name,
                          java.lang.String value,
                          java.lang.String domain,
                          java.lang.String path,
                          long maxAge,
                          boolean httpOnly,
                          boolean secure,
                          java.lang.String comment,
                          int version,
                          HttpCookie.SameSite sameSite)
      • HttpCookie

        public HttpCookie​(java.lang.String setCookie)
    • Method Detail

      • getName

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

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

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

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

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

        public java.lang.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 java.lang.String asString()
        Returns:
        a string representation of this cookie
      • quoteOnlyOrAppend

        private static void quoteOnlyOrAppend​(java.lang.StringBuilder buf,
                                              java.lang.String s,
                                              boolean quote)
      • isQuoteNeededForCookie

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

        public java.lang.String getSetCookie​(CookieCompliance compliance)
      • getRFC2965SetCookie

        public java.lang.String getRFC2965SetCookie()
      • getRFC6265SetCookie

        public java.lang.String getRFC6265SetCookie()
      • isHttpOnlyInComment

        public static boolean isHttpOnlyInComment​(java.lang.String comment)
      • getSameSiteFromComment

        public static HttpCookie.SameSite getSameSiteFromComment​(java.lang.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:
        java.lang.IllegalStateException - if the default value is not a permitted value
      • getCommentWithoutAttributes

        public static java.lang.String getCommentWithoutAttributes​(java.lang.String comment)
      • getCommentWithAttributes

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