// TODO RFC2965 fields also need to be passed
  public static void serializeClientCookies(
      StringBuilder buf,
      boolean versionOneStrictCompliance,
      boolean rfc6265Support,
      Cookie... cookies) {

    if (cookies.length == 0) {
      return;
    }

    final int version = cookies[0].getVersion();

    if (!rfc6265Support && version == 1) {
      buf.append("$Version=\"1\"; ");
    }

    for (int i = 0; i < cookies.length; i++) {
      final Cookie cookie = cookies[i];

      buf.append(cookie.getName());
      buf.append('=');
      // Servlet implementation does not check anything else

      maybeQuote2(version, buf, cookie.getValue(), true, rfc6265Support);

      // If version == 1 - add domain and path
      if (!rfc6265Support && version == 1) {
        // $Domain="domain"
        final String domain = cookie.getDomain();
        if (domain != null) {
          buf.append("; $Domain=");
          maybeQuote2(version, buf, domain, versionOneStrictCompliance, rfc6265Support);
        }

        // $Path="path"
        String path = cookie.getPath();
        if (path != null) {
          buf.append("; $Path=");

          URLEncoder encoder = new URLEncoder();
          encoder.addSafeCharacter('/');
          encoder.addSafeCharacter('"');
          path = encoder.encodeURL(path, true);

          maybeQuote2(
              version,
              buf,
              path,
              tspecials2NoSlash,
              false,
              versionOneStrictCompliance,
              rfc6265Support);
        }
      }

      if (i < cookies.length - 1) {
        buf.append("; ");
      }
    }
  }
  // TODO RFC2965 fields also need to be passed
  public static void serializeServerCookie(
      final Buffer buf,
      final boolean versionOneStrictCompliance,
      final boolean alwaysAddExpires,
      final String name,
      final String value,
      int version,
      String path,
      final String domain,
      final String comment,
      final int maxAge,
      final boolean isSecure,
      final boolean isHttpOnly) {

    // Servlet implementation checks name
    put(buf, name);
    put(buf, '=');
    // Servlet implementation does not check anything else

    version = maybeQuote2(version, buf, value, true);

    // Add version 1 specific information
    if (version == 1) {
      // Version=1 ... required
      put(buf, "; Version=1");

      // Comment=comment
      if (comment != null) {
        put(buf, "; Comment=");
        maybeQuote2(version, buf, comment, versionOneStrictCompliance);
      }
    }

    // Add domain information, if present
    if (domain != null) {
      put(buf, "; Domain=");
      maybeQuote2(version, buf, domain, versionOneStrictCompliance);
    }

    // Max-Age=secs ... or use old "Expires" format
    // TODO RFC2965 Discard
    if (maxAge >= 0) {
      if (version > 0) {
        put(buf, "; Max-Age=");
        putInt(buf, maxAge);
      }
      // IE6, IE7 and possibly other browsers don't understand Max-Age.
      // They do understand Expires, even with V1 cookies!
      if (version == 0 || alwaysAddExpires) {
        // Wdy, DD-Mon-YY HH:MM:SS GMT ( Expires Netscape format )
        put(buf, "; Expires=");
        // To expire immediately we need to set the time in past
        if (maxAge == 0) {
          put(buf, ancientDate);
        } else {
          put(
              buf,
              OLD_COOKIE_FORMAT
                  .get()
                  .format(new Date(System.currentTimeMillis() + maxAge * 1000L)));
        }
      }
    }

    // Path=path
    if (path != null) {
      put(buf, "; Path=");

      URLEncoder encoder = new URLEncoder();
      encoder.addSafeCharacter('/');
      encoder.addSafeCharacter('"');
      path = encoder.encodeURL(path, true);

      if (version == 0) {
        maybeQuote2(version, buf, path, versionOneStrictCompliance);
      } else {
        maybeQuote2(version, buf, path, tspecials2NoSlash, false, versionOneStrictCompliance);
      }
    }

    // Secure
    if (isSecure) {
      put(buf, "; Secure");
    }

    // httpOnly
    if (isHttpOnly) {
      put(buf, "; HttpOnly");
    }
  }