hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebastiano Vigna (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HTTPCLIENT-1429) Very large cookies should be logged in a truncated form
Date Mon, 04 Nov 2013 14:17:21 GMT

    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1429?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13812859#comment-13812859
] 

Sebastiano Vigna commented on HTTPCLIENT-1429:
----------------------------------------------

The current toString() code of BasicClientCookie is 

{code}
    @Override
    public String toString() {
        final StringBuilder buffer = new StringBuilder();
        buffer.append("[version: ");
        buffer.append(Integer.toString(this.cookieVersion));
        buffer.append("]");
        buffer.append("[name: ");
        buffer.append(this.name);
        buffer.append("]");
        buffer.append("[value: ");
        buffer.append(this.value);
        buffer.append("]");
        buffer.append("[domain: ");
        buffer.append(this.cookieDomain);
        buffer.append("]");
        buffer.append("[path: ");
        buffer.append(this.cookiePath);
        buffer.append("]");
        buffer.append("[expiry: ");
        buffer.append(this.cookieExpiryDate);
        buffer.append("]");
        return buffer.toString();
    }
{code}

I would just add 

{code}
    @Override
    public String toString() {
        final StringBuilder buffer = new StringBuilder();
        buffer.append("[version: ");
        buffer.append(Integer.toString(this.cookieVersion));
        buffer.append("]");
        buffer.append("[name: ");
        buffer.append(this.name);
        buffer.append("]");
        buffer.append("[value: ");
        buffer.append(org.apache.commons.lang3.StringUtils.abbreviate(this.value, " ... ",
100 ));
        buffer.append("]");
        buffer.append("[domain: ");
        buffer.append(this.cookieDomain);
        buffer.append("]");
        buffer.append("[path: ");
        buffer.append(this.cookiePath);
        buffer.append("]");
        buffer.append("[expiry: ");
        buffer.append(this.cookieExpiryDate);
        buffer.append("]");
        return buffer.toString();
    }
{code}

Depending on your style, 100 (or another reasonable value) might be replaced with a static
final constant, and I don't know whether you are dependent on lang3 or not, but it's ASF stuff.

> Very large cookies should be logged in a truncated form
> -------------------------------------------------------
>
>                 Key: HTTPCLIENT-1429
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1429
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>          Components: HttpClient
>    Affects Versions: 4.3.1
>            Reporter: Sebastiano Vigna
>            Priority: Minor
>             Fix For: 4.3.2
>
>
> Rejected cookies are logged at WARN level. We have met cookies (usually, binary encoded
state) that are several dozens KB long, and they slow down the logging process significantly.
It would be nice to have a "print/logging-friendly" toString() method that truncates the value
after a few hundred characters or so.



--
This message was sent by Atlassian JIRA
(v6.1#6144)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message