當前位置: 首頁>>代碼示例>>Java>>正文


Java PushPromise類代碼示例

本文整理匯總了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"));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:27,代碼來源:HttpOverHttp2Test.java

示例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"));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:HttpOverHttp2Test.java

示例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"));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:27,代碼來源:HttpOverHttp2Test.java

示例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"));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:HttpOverHttp2Test.java

示例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"));
}
 
開發者ID:lizhangqu,項目名稱:PriorityOkHttp,代碼行數:24,代碼來源:HttpOverHttp2Test.java

示例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"));
}
 
開發者ID:lizhangqu,項目名稱:PriorityOkHttp,代碼行數:24,代碼來源:HttpOverHttp2Test.java


注:本文中的okhttp3.mockwebserver.PushPromise類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。