Package 

Class Cookie

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      public final class Cookie.Builder

      Builds a cookie. The name, value, and domain values must all be set before calling build.

    • Method Summary

      Modifier and Type Method Description
      String name() Returns a non-empty string with this cookie's name.
      String value() Returns a possibly-empty string with this cookie's value.
      boolean persistent() Returns true if this cookie does not expire at the end of the current session.
      long expiresAt() Returns the time that this cookie expires, in the same format as .
      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.
      String domain() Returns the cookie's domain.
      String path() Returns this cookie's path.
      boolean httpOnly() Returns true if this cookie should be limited to only HTTP APIs.
      boolean secure() Returns true if this cookie should be limited to only HTTPS requests.
      boolean matches(HttpUrl url) Returns true if this cookie should be included on a mobonRequest to {@code url}.
      static Cookie parse(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.
      String toString()
      boolean equals(@Nullable() Object other)
      int hashCode()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • name

         String name()

        Returns a non-empty string with this cookie's name.

      • value

         String value()

        Returns a possibly-empty string with this cookie's value.

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