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();
}
}
}
}
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);
}
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);
}
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);
}
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));
}
Aggregations