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


Java CacheResponse.getHeaders方法代碼示例

本文整理匯總了Java中java.net.CacheResponse.getHeaders方法的典型用法代碼示例。如果您正苦於以下問題:Java CacheResponse.getHeaders方法的具體用法?Java CacheResponse.getHeaders怎麽用?Java CacheResponse.getHeaders使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.net.CacheResponse的用法示例。


在下文中一共展示了CacheResponse.getHeaders方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: get

import java.net.CacheResponse; //導入方法依賴的package包/類
@Override public CacheResponse get(URI uri, String requestMethod,
    Map<String, List<String>> requestHeaders) throws IOException {
  final CacheResponse response = delegate.get(uri, requestMethod, requestHeaders);
  if (response instanceof SecureCacheResponse) {
    return new CacheResponse() {
      @Override public InputStream getBody() throws IOException {
        return response.getBody();
      }

      @Override public Map<String, List<String>> getHeaders() throws IOException {
        return response.getHeaders();
      }
    };
  }
  return response;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:ResponseCacheTest.java

示例2: createJavaCacheResponse_httpGet

import java.net.CacheResponse; //導入方法依賴的package包/類
@Test public void createJavaCacheResponse_httpGet() throws Exception {
  Request okRequest =
      createArbitraryOkRequest().newBuilder()
          .url("http://insecure/request")
          .get()
          .build();
  Response okResponse = createArbitraryOkResponse(okRequest).newBuilder()
      .protocol(Protocol.HTTP_1_1)
      .code(200)
      .message("Fantastic")
      .addHeader("key1", "value1_1")
      .addHeader("key2", "value2")
      .addHeader("key1", "value1_2")
      .body(null)
      .build();
  CacheResponse javaCacheResponse = JavaApiConverter.createJavaCacheResponse(okResponse);
  assertFalse(javaCacheResponse instanceof SecureCacheResponse);
  Map<String, List<String>> javaHeaders = javaCacheResponse.getHeaders();
  assertEquals(Arrays.asList("value1_1", "value1_2"), javaHeaders.get("key1"));
  assertEquals(Arrays.asList("HTTP/1.1 200 Fantastic"), javaHeaders.get(null));
  assertNull(javaCacheResponse.getBody());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:JavaApiConverterTest.java

示例3: createJavaCacheResponse_httpPost

import java.net.CacheResponse; //導入方法依賴的package包/類
@Test public void createJavaCacheResponse_httpPost() throws Exception {
  Request okRequest =
      createArbitraryOkRequest().newBuilder()
          .url("http://insecure/request")
          .post(createRequestBody("RequestBody"))
          .build();
  ResponseBody responseBody = createResponseBody("ResponseBody");
  Response okResponse = createArbitraryOkResponse(okRequest).newBuilder()
      .protocol(Protocol.HTTP_1_1)
      .code(200)
      .message("Fantastic")
      .addHeader("key1", "value1_1")
      .addHeader("key2", "value2")
      .addHeader("key1", "value1_2")
      .body(responseBody)
      .build();
  CacheResponse javaCacheResponse = JavaApiConverter.createJavaCacheResponse(okResponse);
  assertFalse(javaCacheResponse instanceof SecureCacheResponse);
  Map<String, List<String>> javaHeaders = javaCacheResponse.getHeaders();
  assertEquals(Arrays.asList("value1_1", "value1_2"), javaHeaders.get("key1"));
  assertEquals(Arrays.asList("HTTP/1.1 200 Fantastic"), javaHeaders.get(null));
  assertEquals("ResponseBody", readAll(javaCacheResponse.getBody()));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:24,代碼來源:JavaApiConverterTest.java

示例4: initResponseSource

import java.net.CacheResponse; //導入方法依賴的package包/類
/**
 * Initialize the source for this response. It may be corrected later if the
 * request headers forbids network use.
 */
private void initResponseSource() throws IOException {
  responseSource = ResponseSource.NETWORK;
  if (!policy.getUseCaches()) return;

  OkResponseCache responseCache = client.getOkResponseCache();
  if (responseCache == null) return;

  CacheResponse candidate = responseCache.get(
      uri, method, requestHeaders.getHeaders().toMultimap(false));
  if (candidate == null) return;

  Map<String, List<String>> responseHeadersMap = candidate.getHeaders();
  cachedResponseBody = candidate.getBody();
  if (!acceptCacheResponseType(candidate)
      || responseHeadersMap == null
      || cachedResponseBody == null) {
    Util.closeQuietly(cachedResponseBody);
    return;
  }

  RawHeaders rawResponseHeaders = RawHeaders.fromMultimap(responseHeadersMap, true);
  cachedResponseHeaders = new ResponseHeaders(uri, rawResponseHeaders);
  long now = System.currentTimeMillis();
  this.responseSource = cachedResponseHeaders.chooseResponseSource(now, requestHeaders);
  if (responseSource == ResponseSource.CACHE) {
    this.cacheResponse = candidate;
    setResponse(cachedResponseHeaders, cachedResponseBody);
  } else if (responseSource == ResponseSource.CONDITIONAL_CACHE) {
    this.cacheResponse = candidate;
  } else if (responseSource == ResponseSource.NETWORK) {
    Util.closeQuietly(cachedResponseBody);
  } else {
    throw new AssertionError();
  }
}
 
開發者ID:aabognah,項目名稱:LoRaWAN-Smart-Parking,代碼行數:40,代碼來源:HttpEngine.java

示例5: extractOkHeaders

import java.net.CacheResponse; //導入方法依賴的package包/類
/**
 * Extracts OkHttp headers from the supplied {@link java.net.CacheResponse}. Only real headers are
 * extracted. See {@link #extractStatusLine(java.net.CacheResponse)}.
 */
private static Headers extractOkHeaders(
    CacheResponse javaResponse, Response.Builder okResponseBuilder) throws IOException {
  Map<String, List<String>> javaResponseHeaders = javaResponse.getHeaders();
  return extractOkHeaders(javaResponseHeaders, okResponseBuilder);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:JavaApiConverter.java

示例6: extractOkHeaders

import java.net.CacheResponse; //導入方法依賴的package包/類
/**
 * Extracts OkHttp headers from the supplied {@link java.net.CacheResponse}. Only real headers are
 * extracted. See {@link #extractStatusLine(java.net.CacheResponse)}.
 */
private static Headers extractOkHeaders(CacheResponse javaResponse) throws IOException {
  Map<String, List<String>> javaResponseHeaders = javaResponse.getHeaders();
  return extractOkHeaders(javaResponseHeaders);
}
 
開發者ID:lizhangqu,項目名稱:PriorityOkHttp,代碼行數:9,代碼來源:JavaApiConverter.java

示例7: extractStatusLine

import java.net.CacheResponse; //導入方法依賴的package包/類
/**
 * Extracts the status line from the supplied Java API {@link java.net.CacheResponse}. As per the
 * spec, the status line is held as the header with the null key. Throws a {@link
 * ProtocolException} if there is no status line.
 */
private static String extractStatusLine(CacheResponse javaResponse) throws IOException {
  Map<String, List<String>> javaResponseHeaders = javaResponse.getHeaders();
  return extractStatusLine(javaResponseHeaders);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:JavaApiConverter.java


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