1
0
mirror of https://github.com/square/okhttp.git synced 2025-11-27 18:21:14 +03:00

Handle unknown content lengths.

This commit is contained in:
Jake Wharton
2016-01-04 13:10:46 -05:00
parent c9080f14f3
commit 8ee07e13d3
2 changed files with 24 additions and 2 deletions

View File

@@ -204,9 +204,11 @@ public final class HttpLoggingInterceptor implements Interceptor {
long tookMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs);
ResponseBody responseBody = response.body();
long contentLength = responseBody.contentLength();
String bodySize = contentLength != -1 ? contentLength + "-byte" : "unknown-length";
logger.log("<-- " + response.code() + ' ' + response.message() + ' '
+ response.request().url() + " (" + tookMs + "ms" + (!logHeaders ? ", "
+ responseBody.contentLength() + "-byte body" : "") + ')');
+ bodySize + " body" : "") + ')');
if (logHeaders) {
Headers headers = response.headers();
@@ -229,7 +231,7 @@ public final class HttpLoggingInterceptor implements Interceptor {
charset = contentType.charset(UTF8);
}
if (responseBody.contentLength() != 0) {
if (contentLength != 0) {
logger.log("");
logger.log(buffer.clone().readString(charset));
}