Class Cookie

    • Nested Class Summary

      Nested Classes

      Modifier and Type Class and Description
      static class  Cookie.Builder
      Builds a cookie.
    • Method Summary

      Modifier and Type Method and Description
      String domain()
      Returns the cookie's domain.
      boolean equals(Object other)
       
      long expiresAt()
      Returns the time that this cookie expires, in the same format as System.currentTimeMillis().
      int hashCode()
       
      boolean hostOnly()
      Returns true if this cookie's domain should be interpreted as a single host name, or false if it should be interpreted as a pattern.
      boolean httpOnly()
      Returns true if this cookie should be limited to only HTTP APIs.
      boolean matches(HttpUrl url)
      Returns true if this cookie should be included on a request to url.
      String name()
      Returns a non-empty string with this cookie's name.
      static Cookie parse(HttpUrl url, String setCookie)
      Attempt to parse a Set-Cookie HTTP header value setCookie as a cookie.
      static List<Cookie> parseAll(HttpUrl url, Headers headers)
      Returns all of the cookies from a set of HTTP response headers.
      String path()
      Returns this cookie's path.
      boolean persistent()
      Returns true if this cookie expires at the end of the current session.
      boolean secure()
      Returns true if this cookie should be limited to only HTTPS requests.
      String toString()
       
      String value()
      Returns a possibly-empty string with this cookie's value.
    • Method Detail

      • name

        public String name()
        Returns a non-empty string with this cookie's name.
      • value

        public String value()
        Returns a possibly-empty string with this cookie's value.
      • persistent

        public boolean persistent()
        Returns true if this cookie expires at the end of the current session.
      • expiresAt

        public long expiresAt()
        Returns the time that this cookie expires, in the same format as System.currentTimeMillis(). This is December 31, 9999 if the cookie is not persistent, in which case it will expire at the end of the current session.

        This may return a value less than the current time, in which case the cookie is already expired. Webservers may return expired cookies as a mechanism to delete previously set cookies that may or may not themselves be expired.

      • hostOnly

        public boolean hostOnly()
        Returns true if this cookie's domain should be interpreted as a single host name, or false if it should be interpreted as a pattern. This flag will be false if its Set-Cookie header included a domain attribute.

        For example, suppose the cookie's domain is example.com. If this flag is true it matches only example.com. If this flag is false it matches example.com and all subdomains including api.example.com, www.example.com, and beta.api.example.com.

      • domain

        public String domain()
        Returns the cookie's domain. If hostOnly() returns true this is the only domain that matches this cookie; otherwise it matches this domain and all subdomains.
      • path

        public String path()
        Returns this cookie's path. This cookie matches URLs prefixed with path segments that match this path's segments. For example, if this path is /foo this cookie matches requests to /foo and /foo/bar, but not / or /football.
      • httpOnly

        public boolean httpOnly()
        Returns true if this cookie should be limited to only HTTP APIs. In web browsers this prevents the cookie from being accessible to scripts.
      • secure

        public boolean secure()
        Returns true if this cookie should be limited to only HTTPS requests.
      • matches

        public boolean matches(HttpUrl url)
        Returns true if this cookie should be included on a request to url. In addition to this check callers should also confirm that this cookie has not expired.
      • parse

        public static Cookie parse(HttpUrl url,
                                   String setCookie)
        Attempt to parse a Set-Cookie HTTP header value setCookie as a cookie. Returns null if setCookie is not a well-formed cookie.
      • parseAll

        public static List<Cookie> parseAll(HttpUrl url,
                                            Headers headers)
        Returns all of the cookies from a set of HTTP response headers.
      • toString

        public String toString()
      • equals

        public boolean equals(Object other)
      • hashCode

        public int hashCode()