本文整理汇总了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;
}
示例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());
}
示例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()));
}
示例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();
}
}
示例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);
}
示例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);
}
示例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);
}