Search in sources :

Example 71 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project NiceMusic by lizixian18.

the class RetrofitHelper method initOkHttpClient.

/**
 * 初始化OKHttpClient,设置缓存,设置超时时间,设置打印日志,设置UA拦截器
 */
private static void initOkHttpClient() {
    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    if (mOkHttpClient == null) {
        synchronized (RetrofitHelper.class) {
            if (mOkHttpClient == null) {
                mOkHttpClient = new OkHttpClient.Builder().addInterceptor(new CommonInterceptor()).addInterceptor(interceptor).addNetworkInterceptor(new CacheInterceptor()).retryOnConnectionFailure(true).connectTimeout(30, TimeUnit.SECONDS).writeTimeout(20, TimeUnit.SECONDS).readTimeout(20, TimeUnit.SECONDS).build();
            }
        }
    }
}
Also used : OkHttpClient(okhttp3.OkHttpClient) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Example 72 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project Tusky by tuskyapp.

the class OkHttpUtils method getCompatibleClientBuilder.

/**
 * Makes a Builder with the maximum range of TLS versions and cipher suites enabled.
 * <p>
 * It first tries the "approved" list of cipher suites given in OkHttp (the default in
 * ConnectionSpec.MODERN_TLS) and if that doesn't work falls back to the set of ALL enabled,
 * then falls back to plain http.
 * <p>
 * API level 24 has a regression in elliptic curves where it only supports secp256r1, so this
 * first tries a fallback without elliptic curves at all, and then tries them after.
 * <p>
 * TLS 1.1 and 1.2 have to be manually enabled on API levels 16-20.
 */
@NonNull
public static OkHttpClient.Builder getCompatibleClientBuilder(SharedPreferences preferences) {
    boolean httpProxyEnabled = preferences.getBoolean("httpProxyEnabled", false);
    String httpServer = preferences.getString("httpProxyServer", "");
    int httpPort = Integer.parseInt(preferences.getString("httpProxyPort", "-1"));
    ConnectionSpec fallback = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS).allEnabledCipherSuites().supportsTlsExtensions(true).build();
    List<ConnectionSpec> specList = new ArrayList<>();
    specList.add(ConnectionSpec.MODERN_TLS);
    addNougatFixConnectionSpec(specList);
    specList.add(fallback);
    specList.add(ConnectionSpec.CLEARTEXT);
    OkHttpClient.Builder builder = new OkHttpClient.Builder().addInterceptor(getUserAgentInterceptor()).readTimeout(30, TimeUnit.SECONDS).writeTimeout(30, TimeUnit.SECONDS).connectionSpecs(specList);
    if (httpProxyEnabled && !httpServer.isEmpty() && (httpPort > 0) && (httpPort < 65535)) {
        InetSocketAddress address = InetSocketAddress.createUnresolved(httpServer, httpPort);
        builder.proxy(new Proxy(Proxy.Type.HTTP, address));
    }
    if (BuildConfig.DEBUG) {
        builder.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BASIC));
    }
    return enableHigherTlsOnPreLollipop(builder);
}
Also used : OkHttpClient(okhttp3.OkHttpClient) ConnectionSpec(okhttp3.ConnectionSpec) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) Proxy(java.net.Proxy) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) NonNull(android.support.annotation.NonNull)

Example 73 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project toshi-android-client by toshiapp.

the class IdService method addLogging.

private void addLogging() {
    final HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(new LoggingInterceptor());
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    this.client.addInterceptor(interceptor);
}
Also used : HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) LoggingInterceptor(com.toshi.manager.network.interceptor.LoggingInterceptor) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Example 74 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project toshi-android-client by toshiapp.

the class ReputationService method addLogging.

private void addLogging() {
    final HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(new LoggingInterceptor());
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    this.client.addInterceptor(interceptor);
}
Also used : HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) LoggingInterceptor(com.toshi.manager.network.interceptor.LoggingInterceptor) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Example 75 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project toshi-android-client by toshiapp.

the class GlideOkHttpStack method registerComponents.

@Override
public void registerComponents(Context context, Glide glide) {
    final File cacheDir = new File(BaseApplication.get().getCacheDir(), "ToshiImageCache");
    final Cache cache = new Cache(cacheDir, MAX_SIZE);
    final OkHttpClient client = new OkHttpClient().newBuilder().cache(cache).addInterceptor(new AppInfoUserAgentInterceptor()).addInterceptor(new HttpLoggingInterceptor(new LoggingInterceptor()).setLevel(HttpLoggingInterceptor.Level.BODY)).build();
    glide.register(CachedGlideUrl.class, InputStream.class, superFactory(new OkHttpUrlLoader.Factory(client), CachedGlideUrl.class));
    glide.register(ForceLoadGlideUrl.class, InputStream.class, superFactory(new OkHttpUrlLoader.Factory(client), ForceLoadGlideUrl.class));
}
Also used : OkHttpClient(okhttp3.OkHttpClient) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) LoggingInterceptor(com.toshi.manager.network.interceptor.LoggingInterceptor) ModelLoaderFactory(com.bumptech.glide.load.model.ModelLoaderFactory) AppInfoUserAgentInterceptor(com.toshi.manager.network.interceptor.AppInfoUserAgentInterceptor) File(java.io.File) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Cache(okhttp3.Cache)

Aggregations

HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)107 OkHttpClient (okhttp3.OkHttpClient)87 Provides (dagger.Provides)27 Retrofit (retrofit2.Retrofit)25 GsonBuilder (com.google.gson.GsonBuilder)24 Singleton (javax.inject.Singleton)24 Cache (okhttp3.Cache)19 Request (okhttp3.Request)16 File (java.io.File)15 Response (okhttp3.Response)15 IOException (java.io.IOException)14 Gson (com.google.gson.Gson)13 Interceptor (okhttp3.Interceptor)11 StethoInterceptor (com.facebook.stetho.okhttp3.StethoInterceptor)6 LoggingInterceptor (com.toshi.manager.network.interceptor.LoggingInterceptor)6 List (java.util.List)5 ErrorInterceptor (me.postaddict.instagram.scraper.interceptor.ErrorInterceptor)5 FakeBrowserInterceptor (me.postaddict.instagram.scraper.interceptor.FakeBrowserInterceptor)5 ResponseBody (okhttp3.ResponseBody)5 BeforeClass (org.junit.BeforeClass)5