本文整理汇总了Java中okhttp3.internal.http.HttpHeaders.hasVaryAll方法的典型用法代码示例。如果您正苦于以下问题:Java HttpHeaders.hasVaryAll方法的具体用法?Java HttpHeaders.hasVaryAll怎么用?Java HttpHeaders.hasVaryAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类okhttp3.internal.http.HttpHeaders
的用法示例。
在下文中一共展示了HttpHeaders.hasVaryAll方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import okhttp3.internal.http.HttpHeaders; //导入方法依赖的package包/类
protected Response execute(Request request) throws IOException {
if (Http.sCache != null) {
if (HttpMethod.invalidatesCache(request.method())) {
try {
Http.sCache.remove(getUrl());
} catch (IOException ignore) {
}
}
if (!"GET".equals(request.method())) {
setShouldCache(false);
}
}
OkHttpClient client = getClient();
Call call = client.newCall(request);
long start = System.currentTimeMillis();
Response response = call.execute();
if (LOG.isLoggable(Log.INFO))
LOG.i("Took " + (System.currentTimeMillis() - start) + "ms to execute request (" + getLogKey() + ")");
if (Http.sCache != null && HttpHeaders.hasVaryAll(response)) {
setShouldCache(false);
}
return response;
}
示例2: varyHeaders
import okhttp3.internal.http.HttpHeaders; //导入方法依赖的package包/类
private static Headers varyHeaders(URLConnection urlConnection, Headers responseHeaders) {
if (HttpHeaders.hasVaryAll(responseHeaders)) {
// "*" means that this will be treated as uncacheable anyway.
return null;
}
Set<String> varyFields = HttpHeaders.varyFields(responseHeaders);
if (varyFields.isEmpty()) {
return new Headers.Builder().build();
}
// This probably indicates another HTTP stack is trying to use the shared ResponseCache.
// We cannot guarantee this case will work properly because we cannot reliably extract *all*
// the request header values, and we can't get multiple Vary request header values.
// We also can't be sure about the Accept-Encoding behavior of other stacks.
if (!(urlConnection instanceof CacheHttpURLConnection
|| urlConnection instanceof CacheHttpsURLConnection)) {
return null;
}
// This is the case we expect: The URLConnection is from a call to
// JavaApiConverter.createJavaUrlConnection() and we have access to the user's request headers.
Map<String, List<String>> requestProperties = urlConnection.getRequestProperties();
Headers.Builder result = new Headers.Builder();
for (String fieldName : varyFields) {
List<String> fieldValues = requestProperties.get(fieldName);
if (fieldValues == null) {
if (fieldName.equals("Accept-Encoding")) {
// Accept-Encoding is special. If OkHttp sees Accept-Encoding is unset it will add
// "gzip". We don't have access to the request that was actually made so we must do the
// same.
result.add("Accept-Encoding", "gzip");
}
} else {
for (String fieldValue : fieldValues) {
Internal.instance.addLenient(result, fieldName, fieldValue);
}
}
}
return result.build();
}
示例3: put
import okhttp3.internal.http.HttpHeaders; //导入方法依赖的package包/类
CacheRequest put(Response response) {
String requestMethod = response.request().method();
if (HttpMethod.invalidatesCache(response.request().method())) {
try {
remove(response.request());
} catch (IOException ignored) {
// The cache cannot be written.
}
return null;
}
if (!requestMethod.equals("GET")) {
// Don't cache non-GET responses. We're technically allowed to cache
// HEAD requests and some POST requests, but the complexity of doing
// so is high and the benefit is low.
return null;
}
if (HttpHeaders.hasVaryAll(response)) {
return null;
}
Entry entry = new Entry(response);
DiskLruCache.Editor editor = null;
try {
editor = cache.edit(key(response.request().url()));
if (editor == null) {
return null;
}
entry.writeTo(editor);
return new CacheRequestImpl(editor);
} catch (IOException e) {
abortQuietly(editor);
return null;
}
}
示例4: put
import okhttp3.internal.http.HttpHeaders; //导入方法依赖的package包/类
@Nullable CacheRequest put(Response response) {
String requestMethod = response.request().method();
if (HttpMethod.invalidatesCache(response.request().method())) {
try {
remove(response.request());
} catch (IOException ignored) {
// The cache cannot be written.
}
return null;
}
if (!requestMethod.equals("GET")) {
// Don't cache non-GET responses. We're technically allowed to cache
// HEAD requests and some POST requests, but the complexity of doing
// so is high and the benefit is low.
return null;
}
if (HttpHeaders.hasVaryAll(response)) {
return null;
}
Entry entry = new Entry(response);
DiskLruCache.Editor editor = null;
try {
editor = cache.edit(key(response.request().url()));
if (editor == null) {
return null;
}
entry.writeTo(editor);
return new CacheRequestImpl(editor);
} catch (IOException e) {
abortQuietly(editor);
return null;
}
}
示例5: put
import okhttp3.internal.http.HttpHeaders; //导入方法依赖的package包/类
private CacheRequest put(Response response) {
String requestMethod = response.request().method();
if (HttpMethod.invalidatesCache(response.request().method())) {
try {
remove(response.request());
} catch (IOException ignored) {
// The cache cannot be written.
}
return null;
}
if (!requestMethod.equals("GET")) {
// Don't cache non-GET responses. We're technically allowed to cache
// HEAD requests and some POST requests, but the complexity of doing
// so is high and the benefit is low.
return null;
}
if (HttpHeaders.hasVaryAll(response)) {
return null;
}
Entry entry = new Entry(response);
DiskLruCache.Editor editor = null;
try {
editor = cache.edit(urlToKey(response.request()));
if (editor == null) {
return null;
}
entry.writeTo(editor);
return new CacheRequestImpl(editor);
} catch (IOException e) {
abortQuietly(editor);
return null;
}
}
示例6: createOkResponseForCacheGet
import okhttp3.internal.http.HttpHeaders; //导入方法依赖的package包/类
/**
* Creates an OkHttp {@link Response} using the supplied {@link Request} and {@link CacheResponse}
* to supply the data.
*/
static Response createOkResponseForCacheGet(Request request, CacheResponse javaResponse)
throws IOException {
// Build a cache request for the response to use.
Headers responseHeaders = createHeaders(javaResponse.getHeaders());
Headers varyHeaders;
if (HttpHeaders.hasVaryAll(responseHeaders)) {
// "*" means that this will be treated as uncacheable anyway.
varyHeaders = new Headers.Builder().build();
} else {
varyHeaders = HttpHeaders.varyHeaders(request.headers(), responseHeaders);
}
Request cacheRequest = new Request.Builder()
.url(request.url())
.method(request.method(), null)
.headers(varyHeaders)
.build();
Response.Builder okResponseBuilder = new Response.Builder();
// Request: Use the cacheRequest we built.
okResponseBuilder.request(cacheRequest);
// Status line: Java has this as one of the headers.
StatusLine statusLine = StatusLine.parse(extractStatusLine(javaResponse));
okResponseBuilder.protocol(statusLine.protocol);
okResponseBuilder.code(statusLine.code);
okResponseBuilder.message(statusLine.message);
// Response headers
Headers okHeaders = extractOkHeaders(javaResponse, okResponseBuilder);
okResponseBuilder.headers(okHeaders);
// Response body
ResponseBody okBody = createOkBody(okHeaders, javaResponse);
okResponseBuilder.body(okBody);
// Handle SSL handshake information as needed.
if (javaResponse instanceof SecureCacheResponse) {
SecureCacheResponse javaSecureCacheResponse = (SecureCacheResponse) javaResponse;
// Handshake doesn't support null lists.
List<Certificate> peerCertificates;
try {
peerCertificates = javaSecureCacheResponse.getServerCertificateChain();
} catch (SSLPeerUnverifiedException e) {
peerCertificates = Collections.emptyList();
}
List<Certificate> localCertificates = javaSecureCacheResponse.getLocalCertificateChain();
if (localCertificates == null) {
localCertificates = Collections.emptyList();
}
String cipherSuiteString = javaSecureCacheResponse.getCipherSuite();
CipherSuite cipherSuite = CipherSuite.forJavaName(cipherSuiteString);
Handshake handshake = Handshake.get(null, cipherSuite, peerCertificates, localCertificates);
okResponseBuilder.handshake(handshake);
}
return okResponseBuilder.build();
}
示例7: createOkResponseForCacheGet
import okhttp3.internal.http.HttpHeaders; //导入方法依赖的package包/类
/**
* Creates an OkHttp {@link Response} using the supplied {@link Request} and {@link CacheResponse}
* to supply the data.
*/
static Response createOkResponseForCacheGet(Request request, CacheResponse javaResponse)
throws IOException {
// Build a cache request for the response to use.
Headers responseHeaders = createHeaders(javaResponse.getHeaders());
Headers varyHeaders;
if (HttpHeaders.hasVaryAll(responseHeaders)) {
// "*" means that this will be treated as uncacheable anyway.
varyHeaders = new Headers.Builder().build();
} else {
varyHeaders = HttpHeaders.varyHeaders(request.headers(), responseHeaders);
}
Request cacheRequest = new Request.Builder()
.url(request.url())
.method(request.method(), null)
.headers(varyHeaders)
.build();
Response.Builder okResponseBuilder = new Response.Builder();
// Request: Use the cacheRequest we built.
okResponseBuilder.request(cacheRequest);
// Status line: Java has this as one of the headers.
StatusLine statusLine = StatusLine.parse(extractStatusLine(javaResponse));
okResponseBuilder.protocol(statusLine.protocol);
okResponseBuilder.code(statusLine.code);
okResponseBuilder.message(statusLine.message);
// Response headers
Headers okHeaders = extractOkHeaders(javaResponse, okResponseBuilder);
okResponseBuilder.headers(okHeaders);
// Response body
ResponseBody okBody = createOkBody(okHeaders, javaResponse);
okResponseBuilder.body(okBody);
// Handle SSL handshake information as needed.
if (javaResponse instanceof SecureCacheResponse) {
SecureCacheResponse javaSecureCacheResponse = (SecureCacheResponse) javaResponse;
// Handshake doesn't support null lists.
List<Certificate> peerCertificates;
try {
peerCertificates = javaSecureCacheResponse.getServerCertificateChain();
} catch (SSLPeerUnverifiedException e) {
peerCertificates = Collections.emptyList();
}
List<Certificate> localCertificates = javaSecureCacheResponse.getLocalCertificateChain();
if (localCertificates == null) {
localCertificates = Collections.emptyList();
}
String cipherSuiteString = javaSecureCacheResponse.getCipherSuite();
CipherSuite cipherSuite = CipherSuite.forJavaName(cipherSuiteString);
Handshake handshake = Handshake.get(
TlsVersion.SSL_3_0, cipherSuite, peerCertificates, localCertificates);
okResponseBuilder.handshake(handshake);
}
return okResponseBuilder.build();
}