Class HttpCookie

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

public class HttpCookie extends Object
  • Field Details

  • 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
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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(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
    • extractBasics

      public static Map<String,String> extractBasics(String setCookieHeader)
      Extract the bare minimum of info from a Set-Cookie header string. Ideally this method should not be necessary, however as java.net.HttpCookie does not yet support generic attributes, we have to use it in a minimal fashion. When it supports attributes, we could look at reverting to a constructor on o.e.j.h.HttpCookie to take the set-cookie header string.
      Parameters:
      setCookieHeader - the header as a string
      Returns:
      a map containing the name, value, domain, path. max-age of the set cookie header
    • 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(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 all of the name, domain and path all match the HttpCookie, false otherwise
    • getCommentWithoutAttributes

      @Deprecated public static String getCommentWithoutAttributes(String comment)
      Deprecated.
      We should not need to do this now
    • getCommentWithAttributes

      @Deprecated public static String getCommentWithAttributes(String comment, boolean httpOnly, HttpCookie.SameSite sameSite)
      Deprecated.
      We should not need to do this now
    • checkSameSite

      public static HttpCookie checkSameSite(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