mirror of
https://github.com/square/okhttp.git
synced 2025-11-26 06:43:09 +03:00
Don't log duplex request bodies
We may want to support these eventually but for now this is unhelpful because they won't terminate.
This commit is contained in:
@@ -20,6 +20,7 @@ import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.MediaType;
|
||||
@@ -796,6 +797,49 @@ public final class HttpLoggingInterceptorTest {
|
||||
.assertNoMoreLogs();
|
||||
}
|
||||
|
||||
@Test public void duplexRequestsAreNotLogged() throws Exception {
|
||||
server.useHttps(handshakeCertificates.sslSocketFactory(), false); // HTTP/2
|
||||
url = server.url("/");
|
||||
|
||||
setLevel(Level.BODY);
|
||||
|
||||
server.enqueue(new MockResponse()
|
||||
.setBody("Hello response!"));
|
||||
|
||||
RequestBody asyncRequestBody = new RequestBody() {
|
||||
@Override public @Nullable MediaType contentType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public void writeTo(BufferedSink sink) throws IOException {
|
||||
sink.writeUtf8("Hello request!");
|
||||
sink.close();
|
||||
}
|
||||
|
||||
@Override public boolean isDuplex() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
Request request = request()
|
||||
.post(asyncRequestBody)
|
||||
.build();
|
||||
Response response = client.newCall(request).execute();
|
||||
assumeThat(response.protocol(), equalTo(Protocol.HTTP_2));
|
||||
|
||||
assertEquals("Hello response!", response.body().string());
|
||||
|
||||
applicationLogs
|
||||
.assertLogEqual("--> POST " + url)
|
||||
.assertLogEqual("--> END POST (duplex request body omitted)")
|
||||
.assertLogMatch("<-- 200 " + url + " \\(\\d+ms\\)")
|
||||
.assertLogEqual("content-length: 15")
|
||||
.assertLogEqual("")
|
||||
.assertLogEqual("Hello response!")
|
||||
.assertLogEqual("<-- END HTTP (15-byte body)")
|
||||
.assertNoMoreLogs();
|
||||
}
|
||||
|
||||
private Request.Builder request() {
|
||||
return new Request.Builder().url(url);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user