Search in sources :

Example 1 with CacheControl

use of okhttp3.CacheControl in project sonarqube by SonarSource.

the class HttpHeadersTest method assertCacheInBrowser.

private static void assertCacheInBrowser(Response httpResponse) {
    CacheControl cacheControl = httpResponse.cacheControl();
    assertThat(cacheControl.mustRevalidate()).isFalse();
    assertThat(cacheControl.noCache()).isFalse();
    assertThat(cacheControl.noStore()).isFalse();
}
Also used : CacheControl(okhttp3.CacheControl)

Example 2 with CacheControl

use of okhttp3.CacheControl in project sonarqube by SonarSource.

the class HttpHeadersTest method assertNoCacheInBrowser.

private static void assertNoCacheInBrowser(Response httpResponse) {
    CacheControl cacheControl = httpResponse.cacheControl();
    assertThat(cacheControl.mustRevalidate()).isTrue();
    assertThat(cacheControl.noCache()).isTrue();
    assertThat(cacheControl.noStore()).isTrue();
}
Also used : CacheControl(okhttp3.CacheControl)

Example 3 with CacheControl

use of okhttp3.CacheControl in project Lightning-Browser by anthonycr.

the class BaseSuggestionsModel method downloadSuggestionsForQuery.

/**
     * This method downloads the search suggestions for the specific query.
     * NOTE: This is a blocking operation, do not getResults on the UI thread.
     *
     * @param query the query to get suggestions for
     * @return the cache file containing the suggestions
     */
@Nullable
private InputStream downloadSuggestionsForQuery(@NonNull String query, @NonNull String language) {
    String queryUrl = createQueryUrl(query, language);
    try {
        URL url = new URL(queryUrl);
        // OkHttp automatically gzips requests
        Request suggestionsRequest = new Request.Builder().url(url).addHeader("Accept-Charset", mEncoding).cacheControl(mCacheControl).build();
        Response suggestionsResponse = mHttpClient.newCall(suggestionsRequest).execute();
        ResponseBody responseBody = suggestionsResponse.body();
        return responseBody != null ? responseBody.byteStream() : null;
    } catch (IOException exception) {
        Log.e(TAG, "Problem getting search suggestions", exception);
    }
    return null;
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) IOException(java.io.IOException) URL(java.net.URL) ResponseBody(okhttp3.ResponseBody) Nullable(android.support.annotation.Nullable)

Example 4 with CacheControl

use of okhttp3.CacheControl in project apps-android-wikipedia by wikimedia.

the class StripMustRevalidateResponseInterceptor method intercept.

@Override
public Response intercept(@NonNull Interceptor.Chain chain) throws IOException {
    Response rsp = chain.proceed(chain.request());
    HttpUrl url = rsp.request().url();
    if (HttpUrlUtil.isRestBase(url) || HttpUrlUtil.isMobileView(url)) {
        String cacheControl = CacheControlUtil.removeDirective(rsp.cacheControl().toString(), "must-revalidate");
        rsp = rsp.newBuilder().header("Cache-Control", cacheControl).build();
    }
    return rsp;
}
Also used : Response(okhttp3.Response) HttpUrl(okhttp3.HttpUrl)

Example 5 with CacheControl

use of okhttp3.CacheControl in project instructure-android by instructure.

the class MobileVerifyAPI method getAuthenticationRetrofit.

private static Retrofit getAuthenticationRetrofit() {
    final String userAgent = ApiPrefs.getUserAgent();
    OkHttpClient httpClient = new OkHttpClient.Builder().addInterceptor(new Interceptor() {

        @Override
        public Response intercept(Chain chain) throws IOException {
            if (!userAgent.equals("")) {
                Request request = chain.request().newBuilder().header("User-Agent", userAgent).cacheControl(CacheControl.FORCE_NETWORK).build();
                return chain.proceed(request);
            } else {
                return chain.proceed(chain.request());
            }
        }
    }).build();
    return new Retrofit.Builder().baseUrl("https://canvas.instructure.com/api/v1/").client(httpClient).addConverterFactory(GsonConverterFactory.create()).build();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) Interceptor(okhttp3.Interceptor)

Aggregations

Request (okhttp3.Request)34 Response (okhttp3.Response)29 CacheControl (okhttp3.CacheControl)16 IOException (java.io.IOException)12 File (java.io.File)10 Interceptor (okhttp3.Interceptor)9 Cache (okhttp3.Cache)8 OkHttpClient (okhttp3.OkHttpClient)6 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)6 Provides (dagger.Provides)4 Singleton (javax.inject.Singleton)4 Call (okhttp3.Call)4 RequestBody (okhttp3.RequestBody)4 Uri (android.net.Uri)3 Map (java.util.Map)3 AsyncTask (android.os.AsyncTask)2 ContentLengthInputStream (com.bumptech.glide.util.ContentLengthInputStream)2 StethoInterceptor (com.facebook.stetho.okhttp3.StethoInterceptor)2 ProgressRequestBody (io.chelizi.amokhttp.upload.ProgressRequestBody)2 FileOutputStream (java.io.FileOutputStream)2