use of okhttp3.Connection in project okhttp by square.
the class Http2ConnectionTest method noPingsAfterShutdown.
@Test
public void noPingsAfterShutdown() throws Exception {
// write the mocking script
peer.sendFrame().settings(new Settings());
// ACK
peer.acceptFrame();
// GOAWAY
peer.acceptFrame();
peer.play();
// play it back
Http2Connection connection = connect(peer);
connection.shutdown(ErrorCode.INTERNAL_ERROR);
try {
connection.ping();
fail();
} catch (ConnectionShutdownException expected) {
}
// verify the peer received what was expected
InFrame goaway = peer.takeFrame();
assertEquals(Http2.TYPE_GOAWAY, goaway.type);
assertEquals(ErrorCode.INTERNAL_ERROR, goaway.errorCode);
}
use of okhttp3.Connection in project okhttp by square.
the class Http2ConnectionTest method remoteSendsRefusedStreamBeforeReplyHeaders.
@Test
public void remoteSendsRefusedStreamBeforeReplyHeaders() throws Exception {
// write the mocking script
peer.sendFrame().settings(new Settings());
// ACK
peer.acceptFrame();
// SYN_STREAM
peer.acceptFrame();
peer.sendFrame().rstStream(3, ErrorCode.REFUSED_STREAM);
peer.sendFrame().ping(false, 2, 0);
// PING
peer.acceptFrame();
peer.play();
// play it back
Http2Connection connection = connect(peer);
Http2Stream stream = connection.newStream(headerEntries("a", "android"), false);
try {
stream.takeResponseHeaders();
fail();
} catch (IOException expected) {
assertEquals("stream was reset: REFUSED_STREAM", expected.getMessage());
}
assertEquals(0, connection.openStreamCount());
// verify the peer received what was expected
InFrame synStream = peer.takeFrame();
assertEquals(Http2.TYPE_HEADERS, synStream.type);
InFrame ping = peer.takeFrame();
assertEquals(Http2.TYPE_PING, ping.type);
assertEquals(2, ping.payload1);
}
use of okhttp3.Connection in project okhttp by square.
the class Http2ConnectionTest method clientClosesClientInputStream.
/**
* Test that the client sends a RST_STREAM if doing so won't disrupt the output stream.
*/
@Test
public void clientClosesClientInputStream() throws Exception {
// write the mocking script
peer.sendFrame().settings(new Settings());
// ACK
peer.acceptFrame();
// SYN_STREAM
peer.acceptFrame();
// RST_STREAM
peer.acceptFrame();
peer.play();
// play it back
Http2Connection connection = connect(peer);
Http2Stream stream = connection.newStream(headerEntries("a", "android"), false);
Source in = stream.getSource();
BufferedSink out = Okio.buffer(stream.getSink());
in.close();
try {
in.read(new Buffer(), 1);
fail();
} catch (IOException expected) {
assertEquals("stream closed", expected.getMessage());
}
try {
out.writeUtf8("a");
out.flush();
fail();
} catch (IOException expected) {
assertEquals("stream finished", expected.getMessage());
}
assertEquals(0, connection.openStreamCount());
// verify the peer received what was expected
InFrame synStream = peer.takeFrame();
assertEquals(Http2.TYPE_HEADERS, synStream.type);
assertTrue(synStream.inFinished);
assertFalse(synStream.outFinished);
InFrame rstStream = peer.takeFrame();
assertEquals(Http2.TYPE_RST_STREAM, rstStream.type);
assertEquals(ErrorCode.CANCEL, rstStream.errorCode);
}
use of okhttp3.Connection in project okhttp by square.
the class Http2ConnectionTest method headers.
@Test
public void headers() throws Exception {
// write the mocking script
peer.sendFrame().settings(new Settings());
// ACK
peer.acceptFrame();
// SYN_STREAM
peer.acceptFrame();
// PING
peer.acceptFrame();
peer.sendFrame().synReply(false, 3, headerEntries("a", "android"));
peer.sendFrame().headers(3, headerEntries("c", "c3po"));
peer.sendFrame().ping(true, 1, 0);
peer.play();
// play it back
Http2Connection connection = connect(peer);
Http2Stream stream = connection.newStream(headerEntries("b", "banana"), true);
// Ensure that the HEADERS has been received.
connection.ping().roundTripTime();
assertEquals(Arrays.asList(new Header("a", "android"), null, new Header("c", "c3po")), stream.takeResponseHeaders());
// verify the peer received what was expected
InFrame synStream = peer.takeFrame();
assertEquals(Http2.TYPE_HEADERS, synStream.type);
InFrame ping = peer.takeFrame();
assertEquals(Http2.TYPE_PING, ping.type);
}
use of okhttp3.Connection in project okhttp by square.
the class Http2ConnectionTest method peerSetsZeroFlowControl.
/**
* Webservers may set the initial window size to zero, which is a special case because it means
* that we have to flush headers immediately before any request body can be sent.
* https://github.com/square/okhttp/issues/2543
*/
@Test
public void peerSetsZeroFlowControl() throws Exception {
peer.setClient(true);
// Write the mocking script.
peer.sendFrame().settings(new Settings().set(INITIAL_WINDOW_SIZE, 0));
// ACK
peer.acceptFrame();
// Increase the connection window size.
peer.sendFrame().windowUpdate(0, 10);
// PING
peer.acceptFrame();
peer.sendFrame().ping(true, 1, 0);
// HEADERS STREAM 3
peer.acceptFrame();
peer.sendFrame().windowUpdate(3, 5);
// DATA STREAM 3 "abcde"
peer.acceptFrame();
peer.sendFrame().windowUpdate(3, 5);
// DATA STREAM 3 "fghi"
peer.acceptFrame();
peer.play();
// Play it back.
Http2Connection connection = connect(peer);
// Ensure the SETTINGS have been received.
connection.ping().roundTripTime();
Http2Stream stream = connection.newStream(headerEntries("a", "android"), true);
BufferedSink sink = Okio.buffer(stream.getSink());
sink.writeUtf8("abcdefghi");
sink.flush();
// Verify the peer received what was expected.
// PING
peer.takeFrame();
InFrame headers = peer.takeFrame();
assertEquals(Http2.TYPE_HEADERS, headers.type);
InFrame data1 = peer.takeFrame();
assertEquals(Http2.TYPE_DATA, data1.type);
assertEquals(3, data1.streamId);
assertTrue(Arrays.equals("abcde".getBytes("UTF-8"), data1.data));
InFrame data2 = peer.takeFrame();
assertEquals(Http2.TYPE_DATA, data2.type);
assertEquals(3, data2.streamId);
assertTrue(Arrays.equals("fghi".getBytes("UTF-8"), data2.data));
}
Aggregations