use of okhttp3.mockwebserver.PushPromise in project okhttp by square.
the class HttpOverHttp2Test method serverSendsPushPromise_GET.
@Test
public void serverSendsPushPromise_GET() throws Exception {
PushPromise pushPromise = new PushPromise("GET", "/foo/bar", Headers.of("foo", "bar"), new MockResponse().setBody("bar").setStatus("HTTP/1.1 200 Sweet"));
server.enqueue(new MockResponse().setBody("ABCDE").setStatus("HTTP/1.1 200 Sweet").withPush(pushPromise));
Call call = client.newCall(new Request.Builder().url(server.url("/foo")).build());
Response response = call.execute();
assertEquals("ABCDE", response.body().string());
assertEquals(200, response.code());
assertEquals("Sweet", response.message());
RecordedRequest request = server.takeRequest();
assertEquals("GET /foo HTTP/1.1", request.getRequestLine());
assertEquals("https", request.getHeader(":scheme"));
assertEquals(server.getHostName() + ":" + server.getPort(), request.getHeader(":authority"));
RecordedRequest pushedRequest = server.takeRequest();
assertEquals("GET /foo/bar HTTP/1.1", pushedRequest.getRequestLine());
assertEquals("bar", pushedRequest.getHeader("foo"));
}
use of okhttp3.mockwebserver.PushPromise in project okhttp by square.
the class HttpOverHttp2Test method serverSendsPushPromise_HEAD.
@Test
public void serverSendsPushPromise_HEAD() throws Exception {
PushPromise pushPromise = new PushPromise("HEAD", "/foo/bar", Headers.of("foo", "bar"), new MockResponse().setStatus("HTTP/1.1 204 Sweet"));
server.enqueue(new MockResponse().setBody("ABCDE").setStatus("HTTP/1.1 200 Sweet").withPush(pushPromise));
Call call = client.newCall(new Request.Builder().url(server.url("/foo")).build());
Response response = call.execute();
assertEquals("ABCDE", response.body().string());
assertEquals(200, response.code());
assertEquals("Sweet", response.message());
RecordedRequest request = server.takeRequest();
assertEquals("GET /foo HTTP/1.1", request.getRequestLine());
assertEquals("https", request.getHeader(":scheme"));
assertEquals(server.getHostName() + ":" + server.getPort(), request.getHeader(":authority"));
RecordedRequest pushedRequest = server.takeRequest();
assertEquals("HEAD /foo/bar HTTP/1.1", pushedRequest.getRequestLine());
assertEquals("bar", pushedRequest.getHeader("foo"));
}
use of okhttp3.mockwebserver.PushPromise in project okhttp by square.
the class Http2ConnectionTest method pushPromiseStreamsAutomaticallyCancel.
@Test
public void pushPromiseStreamsAutomaticallyCancel() throws Exception {
// write the mocking script
peer.sendFrame().settings(new Settings());
// ACK
peer.acceptFrame();
peer.sendFrame().pushPromise(3, 2, Arrays.asList(new Header(Header.TARGET_METHOD, "GET"), new Header(Header.TARGET_SCHEME, "https"), new Header(Header.TARGET_AUTHORITY, "squareup.com"), new Header(Header.TARGET_PATH, "/cached")));
peer.sendFrame().synReply(true, 2, Arrays.asList(new Header(Header.RESPONSE_STATUS, "200")));
// RST_STREAM
peer.acceptFrame();
peer.play();
// play it back
connect(peer, PushObserver.CANCEL, REFUSE_INCOMING_STREAMS);
// verify the peer received what was expected
InFrame rstStream = peer.takeFrame();
assertEquals(Http2.TYPE_RST_STREAM, rstStream.type);
assertEquals(2, rstStream.streamId);
assertEquals(ErrorCode.CANCEL, rstStream.errorCode);
}
Aggregations