Search in sources :

Example 6 with ResponseHeaders

use of com.squareup.okhttp.internal.http.ResponseHeaders in project robovm by robovm.

the class HttpResponseCache method put.

@Override
public CacheRequest put(URI uri, URLConnection urlConnection) throws IOException {
    if (!(urlConnection instanceof HttpURLConnection)) {
        return null;
    }
    HttpURLConnection httpConnection = (HttpURLConnection) urlConnection;
    String requestMethod = httpConnection.getRequestMethod();
    if (maybeRemove(requestMethod, uri)) {
        return null;
    }
    if (!requestMethod.equals("GET")) {
        // so is high and the benefit is low.
        return null;
    }
    HttpEngine httpEngine = getHttpEngine(httpConnection);
    if (httpEngine == null) {
        // Don't cache unless the HTTP implementation is ours.
        return null;
    }
    ResponseHeaders response = httpEngine.getResponseHeaders();
    if (response.hasVaryAll()) {
        return null;
    }
    RawHeaders varyHeaders = httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
    Entry entry = new Entry(uri, varyHeaders, httpConnection);
    DiskLruCache.Editor editor = null;
    try {
        editor = cache.edit(uriToKey(uri));
        if (editor == null) {
            return null;
        }
        entry.writeTo(editor);
        return new CacheRequestImpl(editor);
    } catch (IOException e) {
        abortQuietly(editor);
        return null;
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) HttpEngine(com.squareup.okhttp.internal.http.HttpEngine) DiskLruCache(com.squareup.okhttp.internal.DiskLruCache) IOException(java.io.IOException) ResponseHeaders(com.squareup.okhttp.internal.http.ResponseHeaders) RawHeaders(com.squareup.okhttp.internal.http.RawHeaders)

Aggregations

DiskLruCache (com.squareup.okhttp.internal.DiskLruCache)6 HttpEngine (com.squareup.okhttp.internal.http.HttpEngine)6 RawHeaders (com.squareup.okhttp.internal.http.RawHeaders)6 ResponseHeaders (com.squareup.okhttp.internal.http.ResponseHeaders)6 IOException (java.io.IOException)6 HttpURLConnection (java.net.HttpURLConnection)3 URI (java.net.URI)3