-
public final class CookieAn RFC 6265 Cookie.
This class doesn't support additional attributes on cookies, like Chromium's Priority=HIGH extension.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classCookie.BuilderBuilds a cookie. The name, value, and domain values must all be set before calling build.
-
Method Summary
Modifier and Type Method Description Stringname()Returns a non-empty string with this cookie's name. Stringvalue()Returns a possibly-empty string with this cookie's value. booleanpersistent()Returns true if this cookie does not expire at the end of the current session. longexpiresAt()Returns the time that this cookie expires, in the same format as . booleanhostOnly()Returns true if this cookie's domain should be interpreted as a single host name, or false ifit should be interpreted as a pattern. Stringdomain()Returns the cookie's domain. Stringpath()Returns this cookie's path. booleanhttpOnly()Returns true if this cookie should be limited to only HTTP APIs. booleansecure()Returns true if this cookie should be limited to only HTTPS requests. booleanmatches(HttpUrl url)Returns true if this cookie should be included on a mobonRequest to {@code url}.static Cookieparse(HttpUrl url, String setCookie)Attempt to parse a {@code Set-Cookie}HTTP header value{@code setCookie}as a cookie.static List<Cookie>parseAll(HttpUrl url, Headers headers)Returns all of the cookies from a set of HTTP response headers. StringtoString()booleanequals(@Nullable() Object other)inthashCode()-
-
Method Detail
-
persistent
boolean persistent()
Returns true if this cookie does not expire at the end of the current session.
-
expiresAt
long expiresAt()
Returns the time that this cookie expires, in the same format as . 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 alreadyexpired. Webservers may return expired cookies as a mechanism to delete previously set cookiesthat may or may not themselves be expired.
-
hostOnly
boolean hostOnly()
Returns true if this cookie's domain should be interpreted as a single host name, or false ifit should be interpreted as a pattern. This flag will be false if its
{@code Set-Cookie}headerincluded a{@code domain}attribute.For example, suppose the cookie's domain is
{@code example.com}. If this flag is true itmatches only{@code example.com}. If this flag is false it matches{@code * example.com}and all subdomains including{@code api.example.com},{@code www.example.com}, and{@code beta.api.example.com}.
-
domain
String domain()
Returns the cookie's domain. If hostOnly returns true this is the only domain thatmatches this cookie; otherwise it matches this domain and all subdomains.
-
path
String path()
Returns this cookie's path. This cookie matches URLs prefixed with path segments that matchthis path's segments. For example, if this path is
{@code /foo}this cookie matches requests to{@code /foo}and{@code /foo/bar}, but not{@code /}or{@code /football}.
-
httpOnly
boolean httpOnly()
Returns true if this cookie should be limited to only HTTP APIs. In web browsers this preventsthe cookie from being accessible to scripts.
-
secure
boolean secure()
Returns true if this cookie should be limited to only HTTPS requests.
-
matches
boolean matches(HttpUrl url)
Returns true if this cookie should be included on a mobonRequest to
{@code url}. In addition to thischeck callers should also confirm that this cookie has not expired.
-
parse
@Nullable() static Cookie parse(HttpUrl url, String setCookie)
Attempt to parse a
{@code Set-Cookie}HTTP header value{@code setCookie}as a cookie. Returnsnull if{@code setCookie}is not a well-formed cookie.
-
parseAll
static List<Cookie> parseAll(HttpUrl url, Headers headers)
Returns all of the cookies from a set of HTTP response headers.
-
hashCode
int hashCode()
-
-
-
-