class CookieHeaderProvider implements RuntimeDelegate.HeaderDelegate<Cookie> {

    @Override
    public String toString(Cookie cookie) {
        StringBuilder sb = new StringBuilder();

        if (cookie.getVersion() != Cookie.DEFAULT_VERSION) {
            sb.append(VERSION).append('=').append(cookie.getVersion()).append(';');
        }
        sb.append(cookie.getName()).append('=').append(cookie.getValue());
        if (cookie.getPath() != null) {
            sb.append(';').append(PATH).append('=').append(cookie.getPath());
        }
        if (cookie.getDomain() != null) {
            sb.append(';').append(DOMAIN).append('=').append(cookie.getDomain());
        }
        if (cookie instanceof NewCookie) {
            NewCookie newCookie = (NewCookie) cookie;
            if (newCookie.getMaxAge() != NewCookie.DEFAULT_MAX_AGE) {
                sb.append(';').append(MAX_AGE).append('=').append(newCookie.getMaxAge());
            }
            if (newCookie.getComment() != null) {
                sb.append(';').append(COMMENT).append('=').append(newCookie.getComment());
            }
            if (newCookie.getExpiry() != null) {
                //All HTTP date/time stamps MUST be represented in Greenwich Mean Time (GMT)
                dateFormat.setTimeZone(TimeZone.getTimeZone(GMT_TIMEZONE));
                sb.append(';').append(EXPIRES).append('=').append(dateFormat.format(newCookie.getExpiry()));
            }
            if (newCookie.isSecure()) {
                sb.append(';').append(SECURE);
            }
            if (newCookie.isHttpOnly()) {
                sb.append(';').append(HTTP_ONLY);
            }
        }
        return sb.toString();
    }

}