Module bus.http

Class Cookie

java.lang.Object
org.miaixz.bus.http.Cookie

public final class Cookie extends Object
An RFC 6265-compliant HTTP cookie.

This class supports cookie creation, parsing, and matching. It does not support additional attributes like Chromium's Priority=HIGH extension.

Since:
Java 17+
Author:
Kimi Liu
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    A builder for creating Cookie instances.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the domain of this cookie.
    boolean
    equals(Object other)
    Compares this cookie to another object for equality.
    long
    Returns the expiration time of this cookie.
    int
    Computes the hash code for this cookie.
    boolean
    Returns true if this cookie is host-only.
    boolean
    Returns true if this cookie should only be sent over HTTP APIs.
    boolean
    Returns true if this cookie matches the given URL.
    Returns the name of this cookie.
    static Cookie
    parse(UnoUrl url, String setCookie)
    Parses a Set-Cookie header into a Cookie.
    static List<Cookie>
    parseAll(UnoUrl url, Headers headers)
    Parses all Set-Cookie headers from an HTTP response.
    Returns the path of this cookie.
    boolean
    Returns true if this cookie is persistent.
    boolean
    Returns true if this cookie should only be sent over HTTPS.
    Returns the string representation of this cookie.
    Returns the value of this cookie.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • parse

      public static Cookie parse(UnoUrl url, String setCookie)
      Parses a Set-Cookie header into a Cookie.
      Parameters:
      url - The URL that sent this cookie.
      setCookie - The Set-Cookie header value.
      Returns:
      The parsed cookie, or null if the cookie is invalid.
    • parseAll

      public static List<Cookie> parseAll(UnoUrl url, Headers headers)
      Parses all Set-Cookie headers from an HTTP response.
      Parameters:
      url - The URL that sent these cookies.
      headers - The response headers.
      Returns:
      A list of parsed cookies.
    • name

      public String name()
      Returns the name of this cookie.
      Returns:
      The cookie name.
    • value

      public String value()
      Returns the value of this cookie.
      Returns:
      The cookie value.
    • persistent

      public boolean persistent()
      Returns true if this cookie is persistent.
      Returns:
      true if this cookie is persistent.
    • expiresAt

      public long expiresAt()
      Returns the expiration time of this cookie.
      Returns:
      The expiration time in milliseconds.
    • hostOnly

      public boolean hostOnly()
      Returns true if this cookie is host-only.
      Returns:
      true if this cookie is host-only.
    • domain

      public String domain()
      Returns the domain of this cookie.
      Returns:
      The domain.
    • path

      public String path()
      Returns the path of this cookie.
      Returns:
      The path.
    • httpOnly

      public boolean httpOnly()
      Returns true if this cookie should only be sent over HTTP APIs.
      Returns:
      true if this cookie is HTTP-only.
    • secure

      public boolean secure()
      Returns true if this cookie should only be sent over HTTPS.
      Returns:
      true if this cookie is secure.
    • matches

      public boolean matches(UnoUrl url)
      Returns true if this cookie matches the given URL.
      Parameters:
      url - The URL to check.
      Returns:
      true if this cookie matches the URL.
    • toString

      public String toString()
      Returns the string representation of this cookie.
      Overrides:
      toString in class Object
      Returns:
      The cookie string.
    • equals

      public boolean equals(Object other)
      Compares this cookie to another object for equality.
      Overrides:
      equals in class Object
      Parameters:
      other - The other object to compare against.
      Returns:
      true if the two cookies are equal.
    • hashCode

      public int hashCode()
      Computes the hash code for this cookie.
      Overrides:
      hashCode in class Object
      Returns:
      The hash code value.