本文整理匯總了Java中okhttp3.mockwebserver.PushPromise類的典型用法代碼示例。如果您正苦於以下問題:Java PushPromise類的具體用法?Java PushPromise怎麽用?Java PushPromise使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PushPromise類屬於okhttp3.mockwebserver包,在下文中一共展示了PushPromise類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: serverSendsPushPromise_GET
import okhttp3.mockwebserver.PushPromise; //導入依賴的package包/類
@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"));
}
示例2: serverSendsPushPromise_HEAD
import okhttp3.mockwebserver.PushPromise; //導入依賴的package包/類
@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"));
}
示例3: serverSendsPushPromise_GET
import okhttp3.mockwebserver.PushPromise; //導入依賴的package包/類
@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("", 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"));
}
示例4: serverSendsPushPromise_HEAD
import okhttp3.mockwebserver.PushPromise; //導入依賴的package包/類
@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("", 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"));
}
示例5: serverSendsPushPromise_GET
import okhttp3.mockwebserver.PushPromise; //導入依賴的package包/類
@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"));
MockResponse response = new MockResponse()
.setBody("ABCDE")
.setStatus("HTTP/1.1 200 Sweet")
.withPush(pushPromise);
server.enqueue(response);
connection = urlFactory.open(server.url("/foo").url());
assertContent("ABCDE", connection, Integer.MAX_VALUE);
assertEquals(200, connection.getResponseCode());
assertEquals("Sweet", connection.getResponseMessage());
RecordedRequest request = server.takeRequest();
assertEquals("GET /foo HTTP/1.1", request.getRequestLine());
assertEquals("https", request.getHeader(":scheme"));
assertEquals(server.getHostName() + ":" + server.getPort(), request.getHeader(hostHeader));
RecordedRequest pushedRequest = server.takeRequest();
assertEquals("GET /foo/bar HTTP/1.1", pushedRequest.getRequestLine());
assertEquals("bar", pushedRequest.getHeader("foo"));
}
示例6: serverSendsPushPromise_HEAD
import okhttp3.mockwebserver.PushPromise; //導入依賴的package包/類
@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"));
MockResponse response = new MockResponse()
.setBody("ABCDE")
.setStatus("HTTP/1.1 200 Sweet")
.withPush(pushPromise);
server.enqueue(response);
connection = urlFactory.open(server.url("/foo").url());
assertContent("ABCDE", connection, Integer.MAX_VALUE);
assertEquals(200, connection.getResponseCode());
assertEquals("Sweet", connection.getResponseMessage());
RecordedRequest request = server.takeRequest();
assertEquals("GET /foo HTTP/1.1", request.getRequestLine());
assertEquals("https", request.getHeader(":scheme"));
assertEquals(server.getHostName() + ":" + server.getPort(), request.getHeader(hostHeader));
RecordedRequest pushedRequest = server.takeRequest();
assertEquals("HEAD /foo/bar HTTP/1.1", pushedRequest.getRequestLine());
assertEquals("bar", pushedRequest.getHeader("foo"));
}