okhttp配置缓存拦截器
来源:互联网 发布:apache ssl 自动跳转 编辑:程序博客网 时间:2024/05/08 08:11
public static final Interceptor REWRITE_RESPONSE_INTERCEPTOR = new Interceptor() { @Override public okhttp3.Response intercept(Chain chain) throws IOException { okhttp3.Response originalResponse = chain.proceed(chain.request()); String cacheControl = originalResponse.header("Cache-Control"); if (cacheControl == null || cacheControl.contains("no-store") || cacheControl.contains("no-cache") || cacheControl.contains("must-revalidate") || cacheControl.contains("max-age=0")) { int max_age=60*5; return originalResponse.newBuilder() .removeHeader("Pragma") .header("Cache-Control", "public, max-age=" + max_age) .build(); } else { return originalResponse; } } }; public static Interceptor REWRITE_RESPONSE_INTERCEPTOR_OFFLINE = new Interceptor() { @Override public okhttp3.Response intercept(Chain chain) throws IOException { Request request = chain.request(); if (!NetworkUtils.isConnected()) {// int maxStale = 60 * 60 * 24 * 28;// request = request.newBuilder()// .removeHeader("Pragma")// .header("Cache-Control", "public, only-if-cached,max-stale=" + maxStale)// .build(); request = request.newBuilder() .removeHeader("Pragma") .cacheControl(CacheControl.FORCE_CACHE) .build(); } return chain.proceed(request); } };
阅读全文
0 0
- okhttp配置缓存拦截器
- okhttp之自定义Interceptor:缓存拦截器
- Okhttp的缓存机制+拦截器
- Okhttp缓存配置
- Okhttp 拦截器
- okhttp 拦截器调用。
- OkHttp-Interceptors拦截器
- okhttp拦截器+Imageloader
- OkHttp拦截器
- okhttp拦截器
- Okhttp的拦截器
- okhttp应用拦截器
- okhttp拦截器
- Okhttp网络拦截器
- okhttp添加拦截器
- okhttp网络拦截器
- OkHttp拦截器
- 添加okhttp拦截器
- log4j2的使用
- 程序员不得不珍藏的那些励志片段
- ajax处理从servlet获取的json array
- 顶级人类玩家 Danil Ishutin被AI完败
- java抽象类和接口
- okhttp配置缓存拦截器
- 算法系列-大数据面试题-两个大文件中找出共同记录
- mybatis批量查询
- 第一个springBoot项目,使用模板渲染
- Network-POJ3694并查集+LCA
- c/c++中一些巧妙的方法
- 手机软件分类(自己分)
- php获取当前域名、主机、URL、端口、参数、网址、路径、代理等
- android OOM 内存溢出