当前位置: 首页>>代码示例>>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;未经允许,请勿转载。