use of okhttp3.Interceptor in project CircleDemo by Naoki2015.
the class VideoListGlideModule method createInterceptor.
private static Interceptor createInterceptor(final ResponseProgressListener listener) {
return new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Response response = chain.proceed(request);
return response.newBuilder().body(new OkHttpProgressResponseBody(request.url(), response.body(), listener)).build();
}
};
}
use of okhttp3.Interceptor in project reark by reark.
the class NetworkModule method provideOkHttpClient.
@Provides
@Singleton
public OkHttpClient provideOkHttpClient(@Named("networkInterceptors") List<Interceptor> networkInterceptors) {
OkHttpClient.Builder okBuilder = new OkHttpClient().newBuilder();
okBuilder.networkInterceptors().addAll(networkInterceptors);
return okBuilder.build();
}
use of okhttp3.Interceptor in project Fast-Android-Networking by amitshekhariitbhu.
the class Rx2InternalNetworking method generateDownloadObservable.
public static <T> Observable<T> generateDownloadObservable(final Rx2ANRequest request) {
Request okHttpRequest;
Request.Builder builder = new Request.Builder().url(request.getUrl());
InternalNetworking.addHeadersToRequestBuilder(builder, request);
builder = builder.get();
if (request.getCacheControl() != null) {
builder.cacheControl(request.getCacheControl());
}
okHttpRequest = builder.build();
OkHttpClient okHttpClient;
if (request.getOkHttpClient() != null) {
okHttpClient = request.getOkHttpClient().newBuilder().cache(InternalNetworking.sHttpClient.cache()).addNetworkInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Response originalResponse = chain.proceed(chain.request());
return originalResponse.newBuilder().body(new ResponseProgressBody(originalResponse.body(), request.getDownloadProgressListener())).build();
}
}).build();
} else {
okHttpClient = InternalNetworking.sHttpClient.newBuilder().addNetworkInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Response originalResponse = chain.proceed(chain.request());
return originalResponse.newBuilder().body(new ResponseProgressBody(originalResponse.body(), request.getDownloadProgressListener())).build();
}
}).build();
}
request.setCall(okHttpClient.newCall(okHttpRequest));
return new DownloadANObservable<>(request);
}
use of okhttp3.Interceptor in project bilibili-android-client by HotBitmapGG.
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) {
//设置Http缓存
Cache cache = new Cache(new File(BilibiliApp.getInstance().getCacheDir(), "HttpCache"), 1024 * 1024 * 10);
mOkHttpClient = new OkHttpClient.Builder().cache(cache).addInterceptor(interceptor).addNetworkInterceptor(new CacheInterceptor()).addNetworkInterceptor(new StethoInterceptor()).retryOnConnectionFailure(true).connectTimeout(30, TimeUnit.SECONDS).writeTimeout(20, TimeUnit.SECONDS).readTimeout(20, TimeUnit.SECONDS).addInterceptor(new UserAgentInterceptor()).build();
}
}
}
}
use of okhttp3.Interceptor in project okhttp by square.
the class RealCall method getResponseWithInterceptorChain.
Response getResponseWithInterceptorChain() throws IOException {
// Build a full stack of interceptors.
List<Interceptor> interceptors = new ArrayList<>();
interceptors.addAll(client.interceptors());
interceptors.add(retryAndFollowUpInterceptor);
interceptors.add(new BridgeInterceptor(client.cookieJar()));
interceptors.add(new CacheInterceptor(client.internalCache()));
interceptors.add(new ConnectInterceptor(client));
if (!forWebSocket) {
interceptors.addAll(client.networkInterceptors());
}
interceptors.add(new CallServerInterceptor(forWebSocket));
Interceptor.Chain chain = new RealInterceptorChain(interceptors, null, null, null, 0, originalRequest);
return chain.proceed(originalRequest);
}
Aggregations