HTTPCLIENT-1429: truncate long cookie values in WARN logs

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1539399 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2013-11-06 17:04:21 +00:00
parent 0b3ef4b0d0
commit ebc83e74d2
1 changed files with 24 additions and 4 deletions

View File

@ -114,13 +114,12 @@ public class ResponseProcessCookies implements HttpResponseInterceptor {
cookieStore.addCookie(cookie); cookieStore.addCookie(cookie);
if (this.log.isDebugEnabled()) { if (this.log.isDebugEnabled()) {
this.log.debug("Cookie accepted: \"" this.log.debug("Cookie accepted [" + formatCooke(cookie) + "]");
+ cookie + "\". ");
} }
} catch (final MalformedCookieException ex) { } catch (final MalformedCookieException ex) {
if (this.log.isWarnEnabled()) { if (this.log.isWarnEnabled()) {
this.log.warn("Cookie rejected: \"" this.log.warn("Cookie rejected [" + formatCooke(cookie) + "] "
+ cookie + "\". " + ex.getMessage()); + ex.getMessage());
} }
} }
} }
@ -133,4 +132,25 @@ public class ResponseProcessCookies implements HttpResponseInterceptor {
} }
} }
private static String formatCooke(final Cookie cookie) {
final StringBuilder buf = new StringBuilder();
buf.append(cookie.getName());
buf.append("=\"");
String v = cookie.getValue();
if (v.length() > 100) {
v = v.substring(0, 100) + "...";
}
buf.append(v);
buf.append("\"");
buf.append(", version:");
buf.append(Integer.toString(cookie.getVersion()));
buf.append(", domain:");
buf.append(cookie.getDomain());
buf.append(", path:");
buf.append(cookie.getPath());
buf.append(", expiry:");
buf.append(cookie.getExpiryDate());
return buf.toString();
}
} }