Java Code Examples for com.lzy.okgo.model.HttpHeaders#getLastModified()
The following examples show how to use
com.lzy.okgo.model.HttpHeaders#getLastModified() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HeaderParser.java From okhttp-OkGo with Apache License 2.0 | 3 votes |
/** * 对每个请求添加默认的请求头,如果有缓存,并返回缓存实体对象 * Cache-Control: max-age=0 以秒为单位 * If-Modified-Since: Mon, 19 Nov 2012 08:38:01 GMT 缓存文件的最后修改时间。 * If-None-Match: "0693f67a67cc1:0" 缓存文件的ETag值 * Cache-Control: no-cache 不使用缓存 * Pragma: no-cache 不使用缓存 * Accept-Language: zh-CN,zh;q=0.8 支持的语言 * User-Agent: 用户代理,它的信息包括硬件平台、系统软件、应用软件和用户个人偏好 * Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36 * * @param request 请求类 * @param cacheEntity 缓存实体类 * @param cacheMode 缓存模式 */ public static <T> void addCacheHeaders(Request request, CacheEntity<T> cacheEntity, CacheMode cacheMode) { //1. 按照标准的 http 协议,添加304相关请求头 if (cacheEntity != null && cacheMode == CacheMode.DEFAULT) { HttpHeaders responseHeaders = cacheEntity.getResponseHeaders(); if (responseHeaders != null) { String eTag = responseHeaders.get(HttpHeaders.HEAD_KEY_E_TAG); if (eTag != null) request.headers(HttpHeaders.HEAD_KEY_IF_NONE_MATCH, eTag); long lastModified = HttpHeaders.getLastModified(responseHeaders.get(HttpHeaders.HEAD_KEY_LAST_MODIFIED)); if (lastModified > 0) request.headers(HttpHeaders.HEAD_KEY_IF_MODIFIED_SINCE, HttpHeaders.formatMillisToGMT(lastModified)); } } }
Example 2
Source File: HeaderParser.java From BaseProject with Apache License 2.0 | 3 votes |
/** * 对每个请求添加默认的请求头,如果有缓存,并返回缓存实体对象 * Cache-Control: max-age=0 以秒为单位 * If-Modified-Since: Mon, 19 Nov 2012 08:38:01 GMT 缓存文件的最后修改时间。 * If-None-Match: "0693f67a67cc1:0" 缓存文件的ETag值 * Cache-Control: no-cache 不使用缓存 * Pragma: no-cache 不使用缓存 * Accept-Language: zh-CN,zh;q=0.8 支持的语言 * User-Agent: 用户代理,它的信息包括硬件平台、系统软件、应用软件和用户个人偏好 * Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36 * * @param request 请求类 * @param cacheEntity 缓存实体类 * @param cacheMode 缓存模式 */ public static <T> void addCacheHeaders(Request request, CacheEntity<T> cacheEntity, CacheMode cacheMode) { //1. 按照标准的 http 协议,添加304相关请求头 if (cacheEntity != null && cacheMode == CacheMode.DEFAULT) { HttpHeaders responseHeaders = cacheEntity.getResponseHeaders(); if (responseHeaders != null) { String eTag = responseHeaders.get(HttpHeaders.HEAD_KEY_E_TAG); if (eTag != null) request.headers(HttpHeaders.HEAD_KEY_IF_NONE_MATCH, eTag); long lastModified = HttpHeaders.getLastModified(responseHeaders.get(HttpHeaders.HEAD_KEY_LAST_MODIFIED)); if (lastModified > 0) request.headers(HttpHeaders.HEAD_KEY_IF_MODIFIED_SINCE, HttpHeaders.formatMillisToGMT(lastModified)); } } }