本文整理汇总了Java中okhttp3.internal.http.HttpDate类的典型用法代码示例。如果您正苦于以下问题:Java HttpDate类的具体用法?Java HttpDate怎么用?Java HttpDate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpDate类属于okhttp3.internal.http包,在下文中一共展示了HttpDate类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: maxAge
import okhttp3.internal.http.HttpDate; //导入依赖的package包/类
@Test public void maxAge() throws Exception {
assertEquals(51000L,
Cookie.parse(50000L, url, "a=b; Max-Age=1").expiresAt());
assertEquals(HttpDate.MAX_DATE,
Cookie.parse(50000L, url, "a=b; Max-Age=9223372036854724").expiresAt());
assertEquals(HttpDate.MAX_DATE,
Cookie.parse(50000L, url, "a=b; Max-Age=9223372036854725").expiresAt());
assertEquals(HttpDate.MAX_DATE,
Cookie.parse(50000L, url, "a=b; Max-Age=9223372036854726").expiresAt());
assertEquals(HttpDate.MAX_DATE,
Cookie.parse(9223372036854773807L, url, "a=b; Max-Age=1").expiresAt());
assertEquals(HttpDate.MAX_DATE,
Cookie.parse(9223372036854773807L, url, "a=b; Max-Age=2").expiresAt());
assertEquals(HttpDate.MAX_DATE,
Cookie.parse(9223372036854773807L, url, "a=b; Max-Age=3").expiresAt());
assertEquals(HttpDate.MAX_DATE,
Cookie.parse(50000L, url, "a=b; Max-Age=10000000000000000000").expiresAt());
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:CookieTest.java
示例2: builder
import okhttp3.internal.http.HttpDate; //导入依赖的package包/类
@Test public void builder() throws Exception {
Cookie cookie = new Cookie.Builder()
.name("a")
.value("b")
.domain("example.com")
.build();
assertEquals("a", cookie.name());
assertEquals("b", cookie.value());
assertEquals(HttpDate.MAX_DATE, cookie.expiresAt());
assertEquals("example.com", cookie.domain());
assertEquals("/", cookie.path());
assertFalse(cookie.secure());
assertFalse(cookie.httpOnly());
assertFalse(cookie.persistent());
assertFalse(cookie.hostOnly());
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:CookieTest.java
示例3: isStale
import okhttp3.internal.http.HttpDate; //导入依赖的package包/类
static boolean isStale(Request request, Response response) {
String timeoutStr = request.header(CACHE_EXPIRE_TIMEOUT_HEADER);
String servedDateStr = response.header(CACHE_SERVED_DATE_HEADER);
if (servedDateStr == null || timeoutStr == null) {
return true;
}
long timeout = Long.parseLong(timeoutStr);
if (timeout == 0) {
return false;
}
Date servedDate = HttpDate.parse(servedDateStr);
long now = System.currentTimeMillis();
return servedDate == null || now - servedDate.getTime() > timeout;
}
开发者ID:apollographql,项目名称:apollo-android,代码行数:17,代码来源:Utils.java
示例4: isStale
import okhttp3.internal.http.HttpDate; //导入依赖的package包/类
static boolean isStale(@NonNull final Request request, @NonNull final Response response) {
if (fetchStrategy(request) == HttpCachePolicy.FetchStrategy.CACHE_ONLY) {
return false;
}
String timeoutStr = request.header(CACHE_EXPIRE_TIMEOUT_HEADER);
String servedDateStr = response.header(CACHE_SERVED_DATE_HEADER);
if (servedDateStr == null || timeoutStr == null) {
return true;
}
long timeout = Long.parseLong(timeoutStr);
Date servedDate = HttpDate.parse(servedDateStr);
long now = System.currentTimeMillis();
return servedDate == null || now - servedDate.getTime() > timeout;
}
开发者ID:Shopify,项目名称:mobile-buy-sdk-android,代码行数:18,代码来源:Utils.java
示例5: toString
import okhttp3.internal.http.HttpDate; //导入依赖的package包/类
/**
* @param forObsoleteRfc2965 true to include a leading {@code .} on the domain pattern. This is
* necessary for {@code example.com} to match {@code www.example.com} under RFC 2965. This
* extra dot is ignored by more recent specifications.
*/
String toString(boolean forObsoleteRfc2965) {
StringBuilder result = new StringBuilder();
result.append(name);
result.append('=');
result.append(value);
if (persistent) {
if (expiresAt == Long.MIN_VALUE) {
result.append("; max-age=0");
} else {
result.append("; expires=").append(HttpDate.format(new Date(expiresAt)));
}
}
if (!hostOnly) {
result.append("; domain=");
if (forObsoleteRfc2965) {
result.append(".");
}
result.append(domain);
}
result.append("; path=").append(path);
if (secure) {
result.append("; secure");
}
if (httpOnly) {
result.append("; httponly");
}
return result.toString();
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:40,代码来源:Cookie.java
示例6: Factory
import okhttp3.internal.http.HttpDate; //导入依赖的package包/类
public Factory(long nowMillis, Request request, Response cacheResponse) {
this.nowMillis = nowMillis;
this.request = request;
this.cacheResponse = cacheResponse;
if (cacheResponse != null) {
this.sentRequestMillis = cacheResponse.sentRequestAtMillis();
this.receivedResponseMillis = cacheResponse.receivedResponseAtMillis();
Headers headers = cacheResponse.headers();
for (int i = 0, size = headers.size(); i < size; i++) {
String fieldName = headers.name(i);
String value = headers.value(i);
if ("Date".equalsIgnoreCase(fieldName)) {
servedDate = HttpDate.parse(value);
servedDateString = value;
} else if ("Expires".equalsIgnoreCase(fieldName)) {
expires = HttpDate.parse(value);
} else if ("Last-Modified".equalsIgnoreCase(fieldName)) {
lastModified = HttpDate.parse(value);
lastModifiedString = value;
} else if ("ETag".equalsIgnoreCase(fieldName)) {
etag = value;
} else if ("Age".equalsIgnoreCase(fieldName)) {
ageSeconds = HttpHeaders.parseSeconds(value, -1);
}
}
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:CacheStrategy.java
示例7: invalidYear
import okhttp3.internal.http.HttpDate; //导入依赖的package包/类
@Test public void invalidYear() throws Exception {
assertEquals(HttpDate.MAX_DATE,
Cookie.parse(url, "a=b; Expires=Thu, 01 Jan 1600 00:00:00 GMT").expiresAt());
assertEquals(HttpDate.MAX_DATE,
Cookie.parse(url, "a=b; Expires=Thu, 01 Jan 19999 00:00:00 GMT").expiresAt());
assertEquals(HttpDate.MAX_DATE,
Cookie.parse(url, "a=b; Expires=Thu, 01 Jan 00:00:00 GMT").expiresAt());
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:CookieTest.java
示例8: invalidMonth
import okhttp3.internal.http.HttpDate; //导入依赖的package包/类
@Test public void invalidMonth() throws Exception {
assertEquals(HttpDate.MAX_DATE,
Cookie.parse(url, "a=b; Expires=Thu, 01 Foo 1970 00:00:00 GMT").expiresAt());
assertEquals(HttpDate.MAX_DATE,
Cookie.parse(url, "a=b; Expires=Thu, 01 Foocember 1970 00:00:00 GMT").expiresAt());
assertEquals(HttpDate.MAX_DATE,
Cookie.parse(url, "a=b; Expires=Thu, 01 1970 00:00:00 GMT").expiresAt());
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:CookieTest.java
示例9: setIfModifiedSince
import okhttp3.internal.http.HttpDate; //导入依赖的package包/类
@Override public void setIfModifiedSince(long newValue) {
super.setIfModifiedSince(newValue);
if (ifModifiedSince != 0) {
requestHeaders.set("If-Modified-Since", HttpDate.format(new Date(ifModifiedSince)));
} else {
requestHeaders.removeAll("If-Modified-Since");
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:OkHttpURLConnection.java
示例10: toString
import okhttp3.internal.http.HttpDate; //导入依赖的package包/类
@Override public String toString() {
StringBuilder result = new StringBuilder();
result.append(name);
result.append('=');
result.append(value);
if (persistent) {
if (expiresAt == Long.MIN_VALUE) {
result.append("; max-age=0");
} else {
result.append("; expires=").append(HttpDate.format(new Date(expiresAt)));
}
}
if (!hostOnly) {
result.append("; domain=").append(domain);
}
result.append("; path=").append(path);
if (secure) {
result.append("; secure");
}
if (httpOnly) {
result.append("; httponly");
}
return result.toString();
}
开发者ID:lizhangqu,项目名称:PriorityOkHttp,代码行数:31,代码来源:Cookie.java
示例11: Factory
import okhttp3.internal.http.HttpDate; //导入依赖的package包/类
public Factory(long nowMillis, Request request, Response cacheResponse) {
this.nowMillis = nowMillis;
this.request = request;
this.cacheResponse = cacheResponse;
if (cacheResponse != null) {
//发送请求的时间
this.sentRequestMillis = cacheResponse.sentRequestAtMillis();
//获得响应的时间
this.receivedResponseMillis = cacheResponse.receivedResponseAtMillis();
//缓存中得请求头
Headers headers = cacheResponse.headers();
for (int i = 0, size = headers.size(); i < size; i++) {
String fieldName = headers.name(i);
String value = headers.value(i);
//data,expires,Last-Modified,Age
if ("Date".equalsIgnoreCase(fieldName)) {
servedDate = HttpDate.parse(value);
servedDateString = value;
} else if ("Expires".equalsIgnoreCase(fieldName)) {
expires = HttpDate.parse(value);
} else if ("Last-Modified".equalsIgnoreCase(fieldName)) {
lastModified = HttpDate.parse(value);
lastModifiedString = value;
} else if ("ETag".equalsIgnoreCase(fieldName)) {
etag = value;
} else if ("Age".equalsIgnoreCase(fieldName)) {
ageSeconds = HttpHeaders.parseSeconds(value, -1);
}
}
}
}
开发者ID:RunningTheSnail,项目名称:Okhttp,代码行数:33,代码来源:CacheStrategy.java
示例12: parseDateAsEpoch
import okhttp3.internal.http.HttpDate; //导入依赖的package包/类
/**
* Parse date in RFC1123 format, and return its value as epoch
*/
public static long parseDateAsEpoch(String dateStr) {
try {
// Parse date in RFC1123 format if this header contains one
return HttpDate.parse(dateStr).getTime();
} catch (Exception e) {
// Date in invalid format, fallback to 0
return 0;
}
}
开发者ID:OnelongX,项目名称:GoApp2,代码行数:13,代码来源:HttpHeaderParser.java
示例13: addCacheHeaders
import okhttp3.internal.http.HttpDate; //导入依赖的package包/类
private void addCacheHeaders(Map<String, String> headers, Cache.Entry entry) {
// If there's no cache entry, we're done.
if (entry == null) {
return;
}
if (entry.etag != null) {
headers.put("If-None-Match", entry.etag);
}
if (entry.serverDate > 0) {
Date refTime = new Date(entry.serverDate);
headers.put("If-Modified-Since", HttpDate.format(refTime));
}
}
开发者ID:OnelongX,项目名称:GoApp2,代码行数:16,代码来源:BasicNetwork.java
示例14: getDate
import okhttp3.internal.http.HttpDate; //导入依赖的package包/类
/**
* Returns the last value corresponding to the specified field parsed as an HTTP date, or null if
* either the field is absent or cannot be parsed as a date.
*/
public Date getDate(String name) {
String value = get(name);
return value != null ? HttpDate.parse(value) : null;
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:Headers.java
示例15: invalidDayOfMonth
import okhttp3.internal.http.HttpDate; //导入依赖的package包/类
@Test public void invalidDayOfMonth() throws Exception {
assertEquals(HttpDate.MAX_DATE,
Cookie.parse(url, "a=b; Expires=Thu, 32 Jan 1970 00:00:00 GMT").expiresAt());
assertEquals(HttpDate.MAX_DATE,
Cookie.parse(url, "a=b; Expires=Thu, Jan 1970 00:00:00 GMT").expiresAt());
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:7,代码来源:CookieTest.java
示例16: invalidHour
import okhttp3.internal.http.HttpDate; //导入依赖的package包/类
@Test public void invalidHour() throws Exception {
assertEquals(HttpDate.MAX_DATE,
Cookie.parse(url, "a=b; Expires=Thu, 01 Jan 1970 24:00:00 GMT").expiresAt());
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:5,代码来源:CookieTest.java
示例17: invalidMinute
import okhttp3.internal.http.HttpDate; //导入依赖的package包/类
@Test public void invalidMinute() throws Exception {
assertEquals(HttpDate.MAX_DATE,
Cookie.parse(url, "a=b; Expires=Thu, 01 Jan 1970 00:60:00 GMT").expiresAt());
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:5,代码来源:CookieTest.java
示例18: invalidSecond
import okhttp3.internal.http.HttpDate; //导入依赖的package包/类
@Test public void invalidSecond() throws Exception {
assertEquals(HttpDate.MAX_DATE,
Cookie.parse(url, "a=b; Expires=Thu, 01 Jan 1970 00:00:60 GMT").expiresAt());
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:5,代码来源:CookieTest.java
示例19: getDate
import okhttp3.internal.http.HttpDate; //导入依赖的package包/类
/**
* Returns the last value corresponding to the specified field parsed as an HTTP date, or null if
* either the field is absent or cannot be parsed as a date.
*/
public @Nullable Date getDate(String name) {
String value = get(name);
return value != null ? HttpDate.parse(value) : null;
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:Headers.java
注:本文中的okhttp3.internal.http.HttpDate类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论