static String encode(boolean strict, Cookie cookie) {
        final String name = requireNonNull(cookie, "cookie").name();
        final String value = firstNonNull(cookie.value(), "");

        validateCookie(strict, name, value);

        final StringBuilder buf = stringBuilder();

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

        if (cookie.maxAge() != Long.MIN_VALUE) {
            add(buf, CookieHeaderNames.MAX_AGE, cookie.maxAge());
            final Date expires = new Date(cookie.maxAge() * 1000 + System.currentTimeMillis());
            buf.append(CookieHeaderNames.EXPIRES);
            buf.append('=');
            DateFormatter.append(expires, buf);
            buf.append(';');
            buf.append(HttpConstants.SP_CHAR);
        }

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

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

        return stripTrailingSeparator(buf);
    }
Encodes the specified {@link Cookie} into a {@code "Set-Cookie"} header value.

@param strict whether to validate that name and value chars are in the valid scope defined in RFC 6265.
@param cookie the {@link Cookie} to encode.
@return a single {@code "Set-Cookie"} header value.
core/src/main/java/com/linecorp/armeria/common/ServerCookieEncoder.java