use of com.eveningoutpost.dexdrip.cgm.nsfollow.GzipRequestInterceptor in project xDrip by NightscoutFoundation.
the class RetrofitBase method getRetrofitInstance.
// TODO make fully reusable
public static Retrofit getRetrofitInstance(final String TAG, final String url, boolean useGzip) throws IllegalArgumentException {
Retrofit instance = instances.get(TAG);
if (instance == null || !urls.get(TAG).equals(url)) {
synchronized (instances) {
if (emptyString(url)) {
UserError.Log.d(TAG, "Empty url - cannot create instance");
return null;
}
UserError.Log.d(TAG, "Creating new instance for: " + url);
final OkHttpClient.Builder httpClient = enableTls12OnPreLollipop(new OkHttpClient.Builder()).addInterceptor(new InfoInterceptor(TAG)).addInterceptor(useGzip ? new GzipRequestInterceptor() : new NullInterceptor());
if (UserError.ExtraLogTags.shouldLogTag(TAG, android.util.Log.VERBOSE)) {
UserError.Log.v(TAG, "Enable logging of request and response lines and their respective headers and bodies.");
final HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
httpLoggingInterceptor.redactHeader("Authorization");
httpLoggingInterceptor.redactHeader("Cookie");
httpClient.addInterceptor(httpLoggingInterceptor);
}
instances.put(TAG, instance = new retrofit2.Retrofit.Builder().baseUrl(url).client(httpClient.build()).addConverterFactory(createGsonConverter(Dex_Constants.TREND_ARROW_VALUES.class, new ShareTrendDeserializer())).build());
// save creation url for quick search
urls.put(TAG, url);
}
}
return instance;
}
use of com.eveningoutpost.dexdrip.cgm.nsfollow.GzipRequestInterceptor in project xDrip-plus by jamorham.
the class RetrofitBase method getRetrofitInstance.
// TODO make fully reusable
public static Retrofit getRetrofitInstance(final String TAG, final String url, boolean useGzip) throws IllegalArgumentException {
Retrofit instance = instances.get(TAG);
if (instance == null || !urls.get(TAG).equals(url)) {
synchronized (instances) {
if (emptyString(url)) {
UserError.Log.d(TAG, "Empty url - cannot create instance");
return null;
}
UserError.Log.d(TAG, "Creating new instance for: " + url);
final OkHttpClient.Builder httpClient = enableTls12OnPreLollipop(new OkHttpClient.Builder()).addInterceptor(new InfoInterceptor(TAG)).addInterceptor(useGzip ? new GzipRequestInterceptor() : new NullInterceptor());
if (UserError.ExtraLogTags.shouldLogTag(TAG, android.util.Log.VERBOSE)) {
UserError.Log.v(TAG, "Enable logging of request and response lines and their respective headers and bodies.");
final HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
httpLoggingInterceptor.redactHeader("Authorization");
httpLoggingInterceptor.redactHeader("Cookie");
httpClient.addInterceptor(httpLoggingInterceptor);
}
instances.put(TAG, instance = new retrofit2.Retrofit.Builder().baseUrl(url).client(httpClient.build()).addConverterFactory(createGsonConverter(Dex_Constants.TREND_ARROW_VALUES.class, new ShareTrendDeserializer())).build());
// save creation url for quick search
urls.put(TAG, url);
}
}
return instance;
}
Aggregations