public final class Cookie extends Object
This class doesn't support additional attributes on cookies, like Chromium's Priority=HIGH extension.
| Modifier and Type | Class and Description |
|---|---|
static class |
Cookie.Builder
Builds a cookie.
|
| 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 does not expire 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.
|
public String name()
public String value()
public boolean persistent()
public long expiresAt()
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.
public boolean hostOnly()
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.
public String domain()
hostOnly() returns true this is the only domain that
matches this cookie; otherwise it matches this domain and all subdomains.public String path()
/foo this cookie matches requests to
/foo and /foo/bar, but not / or /football.public boolean httpOnly()
public boolean secure()
public boolean matches(HttpUrl url)
url. In addition to this
check callers should also confirm that this cookie has not expired.@Nullable public static Cookie parse(HttpUrl url, String setCookie)
Set-Cookie HTTP header value setCookie as a cookie. Returns
null if setCookie is not a well-formed cookie.public static List<Cookie> parseAll(HttpUrl url, Headers headers)
Copyright © 2017. All Rights Reserved.