core/play/src/main/java/play/core/cookie/encoding/ServerCookieEncoder.java
public String encode(Cookie cookie) {
    if (cookie == null) {
      throw new NullPointerException("cookie");
    }
    final String name = cookie.name();
    final String value = cookie.value() != null ? cookie.value() : "";

    validateCookie(name, value);

    StringBuilder buf = new StringBuilder();

    if (cookie.wrap()) {
      addQuoted(buf, name, value);
    } else {
      add(buf, name, value);
    }

    if (cookie.maxAge() != Integer.MIN_VALUE) {
      add(buf, CookieHeaderNames.MAX_AGE, cookie.maxAge());
      Date expires =
          cookie.maxAge() <= 0
              ? new Date(0) // Set expires to the Unix epoch
              : new Date(cookie.maxAge() * 1000L + System.currentTimeMillis());
      add(buf, CookieHeaderNames.EXPIRES, HttpHeaderDateFormat.get().format(expires));
    }

    if (cookie.sameSite() != null) {
      add(buf, CookieHeaderNames.SAMESITE, cookie.sameSite());
    }

    if (cookie.path() != null) {
      add(buf, CookieHeaderNames.PATH, cookie.path());
    }

    if (cookie.domain() != null) {
      add(buf, CookieHeaderNames.DOMAIN, cookie.domain());
    }
    if (cookie.isSecure()) {
      add(buf, CookieHeaderNames.SECURE);
    }
    if (cookie.isHttpOnly()) {
      add(buf, CookieHeaderNames.HTTPONLY);
    }

    return stripTrailingSeparator(buf);
  }
public String encode(Cookie cookie) {
    if (cookie == null) {
      throw new NullPointerException("cookie");
    }
    final String name = cookie.name();
    final String value = cookie.value() != null ? cookie.value() : "";

    validateCookie(name, value);

    StringBuilder buf = new StringBuilder();

    if (cookie.wrap()) {
      addQuoted(buf, name, value);
    } else {
      add(buf, name, value);
    }

    if (cookie.maxAge() != Integer.MIN_VALUE) {
      add(buf, CookieHeaderNames.MAX_AGE, cookie.maxAge());
      Date expires =
          cookie.maxAge() <= 0
              ? new Date(0) // Set expires to the Unix epoch
              : new Date(cookie.maxAge() * 1000L + System.currentTimeMillis());
      add(buf, CookieHeaderNames.EXPIRES, HttpHeaderDateFormat.get().format(expires));
    }

    if (cookie.sameSite() != null) {
      add(buf, CookieHeaderNames.SAMESITE, cookie.sameSite());
    }

    if (cookie.path() != null) {
      add(buf, CookieHeaderNames.PATH, cookie.path());
    }

    if (cookie.domain() != null) {
      add(buf, CookieHeaderNames.DOMAIN, cookie.domain());
    }
    if (cookie.isSecure()) {
      add(buf, CookieHeaderNames.SECURE);
    }
    if (cookie.isHttpOnly()) {
      add(buf, CookieHeaderNames.HTTPONLY);
    }

    return stripTrailingSeparator(buf);
  }
Encodes the specified cookie into a Set-Cookie header value.

@param cookie the cookie
@return a single Set-Cookie header value