1
0
mirror of https://github.com/square/okhttp.git synced 2025-11-24 18:41:06 +03:00

Omit the message from MockWebServer's HTTP/2 :status header (#3556)

This was a bug carried over from SPDY.

Closes: https://github.com/square/okhttp/issues/3484
This commit is contained in:
Jesse Wilson
2017-08-30 18:25:44 -04:00
committed by GitHub
parent ee5cf50288
commit 207f5579d3
5 changed files with 15 additions and 12 deletions

View File

@@ -219,9 +219,11 @@ public final class HttpLoggingInterceptor implements Interceptor {
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 ? ", "
+ bodySize + " body" : "") + ')');
logger.log("<-- "
+ response.code()
+ (response.message().isEmpty() ? "" : ' ' + response.message())
+ ' ' + response.request().url()
+ " (" + tookMs + "ms" + (!logHeaders ? ", " + bodySize + " body" : "") + ')');
if (logHeaders) {
Headers headers = response.headers();

View File

@@ -43,11 +43,13 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeThat;
public final class HttpLoggingInterceptorTest {
private static final MediaType PLAIN = MediaType.parse("text/plain; charset=utf-8");
@@ -685,16 +687,16 @@ public final class HttpLoggingInterceptorTest {
server.enqueue(new MockResponse());
Response response = client.newCall(request().build()).execute();
assertEquals(Protocol.HTTP_2, response.protocol());
assumeThat(response.protocol(), equalTo(Protocol.HTTP_2));
applicationLogs
.assertLogEqual("--> GET " + url)
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, 0-byte body\\)")
.assertLogMatch("<-- 200 " + url + " \\(\\d+ms, 0-byte body\\)")
.assertNoMoreLogs();
networkLogs
.assertLogEqual("--> GET " + url + " h2")
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, 0-byte body\\)")
.assertLogMatch("<-- 200 " + url + " \\(\\d+ms, 0-byte body\\)")
.assertNoMoreLogs();
}