use of okhttp3.internal.SocketRecorder in project okhttp by square.
the class HttpOverHttp2Test method emptyDataFrameSentWithEmptyBody.
@Test
public void emptyDataFrameSentWithEmptyBody() throws Exception {
server.enqueue(new MockResponse().setBody("ABC"));
SocketRecorder socketRecorder = new SocketRecorder();
client = client.newBuilder().sslSocketFactory(socketRecorder.sslSocketFactory(sslClient.socketFactory), sslClient.trustManager).build();
Call call = client.newCall(new Request.Builder().url(server.url("/")).method("DELETE", Util.EMPTY_REQUEST).build());
Response response = call.execute();
assertEquals("ABC", response.body().string());
// Replay the bytes written by the client to confirm an empty data frame was sent.
SocketRecorder.RecordedSocket recordedSocket = socketRecorder.takeSocket();
Buffer buffer = new Buffer();
buffer.write(recordedSocket.bytesWritten());
RecordingHandler handler = new RecordingHandler();
Http2Reader reader = new Http2Reader(buffer, false);
reader.readConnectionPreface(null);
while (reader.nextFrame(false, handler)) {
}
assertEquals(1, handler.headerFrameCount);
assertEquals(Collections.singletonList(0), handler.dataFrames);
}
use of okhttp3.internal.SocketRecorder in project okhttp by square.
the class HttpOverHttp2Test method noDataFramesSentWithNullRequestBody.
@Test
public void noDataFramesSentWithNullRequestBody() throws Exception {
server.enqueue(new MockResponse().setBody("ABC"));
SocketRecorder socketRecorder = new SocketRecorder();
client = client.newBuilder().sslSocketFactory(socketRecorder.sslSocketFactory(sslClient.socketFactory), sslClient.trustManager).build();
Call call = client.newCall(new Request.Builder().url(server.url("/")).method("DELETE", null).build());
Response response = call.execute();
assertEquals("ABC", response.body().string());
// Replay the bytes written by the client to confirm no data frames were sent.
SocketRecorder.RecordedSocket recordedSocket = socketRecorder.takeSocket();
Buffer buffer = new Buffer();
buffer.write(recordedSocket.bytesWritten());
RecordingHandler handler = new RecordingHandler();
Http2Reader reader = new Http2Reader(buffer, false);
reader.readConnectionPreface(null);
while (reader.nextFrame(false, handler)) {
}
assertEquals(1, handler.headerFrameCount);
assertTrue(handler.dataFrames.isEmpty());
}
Aggregations