Skip to content

Commit 207f557

Browse files
authored
Omit the message from MockWebServer's HTTP/2 :status header (square#3556)
This was a bug carried over from SPDY. Closes: square#3484
1 parent ee5cf50 commit 207f557

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

mockwebserver/src/main/java/okhttp3/mockwebserver/MockWebServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -938,8 +938,8 @@ private void writeResponse(Http2Stream stream, MockResponse response) throws IOE
938938
return;
939939
}
940940
List<Header> http2Headers = new ArrayList<>();
941-
String[] statusParts = response.getStatus().split(" ", 2);
942-
if (statusParts.length != 2) {
941+
String[] statusParts = response.getStatus().split(" ", 3);
942+
if (statusParts.length < 2) {
943943
throw new AssertionError("Unexpected status: " + response.getStatus());
944944
}
945945
// TODO: constants for well-known header names.

okhttp-logging-interceptor/src/main/java/okhttp3/logging/HttpLoggingInterceptor.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,11 @@ public Level getLevel() {
219219
ResponseBody responseBody = response.body();
220220
long contentLength = responseBody.contentLength();
221221
String bodySize = contentLength != -1 ? contentLength + "-byte" : "unknown-length";
222-
logger.log("<-- " + response.code() + ' ' + response.message() + ' '
223-
+ response.request().url() + " (" + tookMs + "ms" + (!logHeaders ? ", "
224-
+ bodySize + " body" : "") + ')');
222+
logger.log("<-- "
223+
+ response.code()
224+
+ (response.message().isEmpty() ? "" : ' ' + response.message())
225+
+ ' ' + response.request().url()
226+
+ " (" + tookMs + "ms" + (!logHeaders ? ", " + bodySize + " body" : "") + ')');
225227

226228
if (logHeaders) {
227229
Headers headers = response.headers();

okhttp-logging-interceptor/src/test/java/okhttp3/logging/HttpLoggingInterceptorTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@
4343
import org.junit.Rule;
4444
import org.junit.Test;
4545

46+
import static org.hamcrest.CoreMatchers.equalTo;
4647
import static org.junit.Assert.assertEquals;
4748
import static org.junit.Assert.assertFalse;
4849
import static org.junit.Assert.assertSame;
4950
import static org.junit.Assert.assertTrue;
5051
import static org.junit.Assert.fail;
52+
import static org.junit.Assume.assumeThat;
5153

5254
public final class HttpLoggingInterceptorTest {
5355
private static final MediaType PLAIN = MediaType.parse("text/plain; charset=utf-8");
@@ -685,16 +687,16 @@ private void bodyGetNoBody(int code) throws IOException {
685687

686688
server.enqueue(new MockResponse());
687689
Response response = client.newCall(request().build()).execute();
688-
assertEquals(Protocol.HTTP_2, response.protocol());
690+
assumeThat(response.protocol(), equalTo(Protocol.HTTP_2));
689691

690692
applicationLogs
691693
.assertLogEqual("--> GET " + url)
692-
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, 0-byte body\\)")
694+
.assertLogMatch("<-- 200 " + url + " \\(\\d+ms, 0-byte body\\)")
693695
.assertNoMoreLogs();
694696

695697
networkLogs
696698
.assertLogEqual("--> GET " + url + " h2")
697-
.assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, 0-byte body\\)")
699+
.assertLogMatch("<-- 200 " + url + " \\(\\d+ms, 0-byte body\\)")
698700
.assertNoMoreLogs();
699701
}
700702

okhttp-tests/src/test/java/okhttp3/CallTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2326,7 +2326,6 @@ private void cancelDuringConnect(String scheme) throws Exception {
23262326
Call call = client.newCall(request);
23272327
Response response = call.execute();
23282328
assertEquals(100, response.code());
2329-
assertEquals("Continue", response.message());
23302329
assertEquals("", response.body().string());
23312330

23322331
RecordedRequest recordedRequest = server.takeRequest();

okhttp-tests/src/test/java/okhttp3/internal/http2/HttpOverHttp2Test.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public final class HttpOverHttp2Test {
119119

120120
assertEquals("ABCDE", response.body().string());
121121
assertEquals(200, response.code());
122-
assertEquals("Sweet", response.message());
122+
assertEquals("", response.message());
123123

124124
RecordedRequest request = server.takeRequest();
125125
assertEquals("GET /foo HTTP/1.1", request.getRequestLine());
@@ -766,7 +766,7 @@ private void noRecoveryFromErrorWithRetryDisabled(ErrorCode errorCode) throws Ex
766766

767767
assertEquals("ABCDE", response.body().string());
768768
assertEquals(200, response.code());
769-
assertEquals("Sweet", response.message());
769+
assertEquals("", response.message());
770770

771771
RecordedRequest request = server.takeRequest();
772772
assertEquals("GET /foo HTTP/1.1", request.getRequestLine());
@@ -792,7 +792,7 @@ private void noRecoveryFromErrorWithRetryDisabled(ErrorCode errorCode) throws Ex
792792
Response response = call.execute();
793793
assertEquals("ABCDE", response.body().string());
794794
assertEquals(200, response.code());
795-
assertEquals("Sweet", response.message());
795+
assertEquals("", response.message());
796796

797797
RecordedRequest request = server.takeRequest();
798798
assertEquals("GET /foo HTTP/1.1", request.getRequestLine());

0 commit comments

Comments
 (0)