Java 类org.apache.http.impl.cookie.DateUtils 实例源码

项目:SaveVolley    文件:BasicNetwork.java   
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) {
        // 设置 If-None-Match
        headers.put("If-None-Match", entry.etag);
    }

    if (entry.lastModified > 0) {
        Date refTime = new Date(entry.lastModified);
        // 设置 If-Modified-Since
        headers.put("If-Modified-Since", DateUtils.formatDate(refTime));
    }
}
项目:purecloud-iot    文件:CachingHttpClient.java   
private boolean revalidationResponseIsTooOld(final HttpResponse backendResponse,
        final HttpCacheEntry cacheEntry) {
    final Header entryDateHeader = cacheEntry.getFirstHeader(HTTP.DATE_HEADER);
    final Header responseDateHeader = backendResponse.getFirstHeader(HTTP.DATE_HEADER);
    if (entryDateHeader != null && responseDateHeader != null) {
        try {
            final Date entryDate = DateUtils.parseDate(entryDateHeader.getValue());
            final Date respDate = DateUtils.parseDate(responseDateHeader.getValue());
            if (respDate.before(entryDate)) {
                return true;
            }
        } catch (final DateParseException e) {
            // either backend response or cached entry did not have a valid
            // Date header, so we can't tell if they are out of order
            // according to the origin clock; thus we can skip the
            // unconditional retry recommended in 13.2.6 of RFC 2616.
        }
    }
    return false;
}
项目:jira-dvcs-connector    文件:EtagCachingHttpClientTest.java   
@Test
public void execute() throws ClientProtocolException, IOException
{
    EtagAnswer answer = new EtagAnswer();

    Mockito.when(httpClient.execute(Matchers.any(HttpUriRequest.class), Matchers.any(HttpContext.class))).then(answer);

    EtagCachingHttpClient client = new EtagCachingHttpClient(httpClient);

    HttpResponse response = client.execute(prepareRequest(null, null));
    checkResponse(response, DateUtils.formatDate(answer.getLastModified()));
    Assert.assertTrue(answer.isModified());

    response = client.execute(prepareRequest(null, null));
    checkResponse(response, DateUtils.formatDate(answer.getLastModified()));
    Assert.assertFalse(answer.isModified());
}
项目:jira-dvcs-connector    文件:EtagCachingHttpClientTest.java   
@Test
public void executeWithModifiedSince() throws ClientProtocolException, IOException
{
    EtagAnswer answer = new EtagAnswer();

    Mockito.when(httpClient.execute(Matchers.any(HttpUriRequest.class), Matchers.any(HttpContext.class))).then(answer);

    EtagCachingHttpClient client = new EtagCachingHttpClient(httpClient);

    HttpResponse response = client.execute(prepareRequest(null, null));
    checkResponse(response, DateUtils.formatDate(answer.getLastModified()));
    Assert.assertTrue(answer.isModified());
    Header lastModifiedHeader = response.getFirstHeader(HeaderConstants.LAST_MODIFIED);
    String lastModified = lastModifiedHeader.getValue();

    response = client.execute(prepareRequest(null, lastModified));
    checkResponse(response, lastModified);
    Assert.assertFalse(answer.isModified());
}
项目:BookMySkills    文件:BasicNetwork.java   
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", DateUtils.formatDate(refTime));
    }
}
项目:AndroidLife    文件:BasicNetwork.java   
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) {
        // 设置 If-None-Match
        headers.put("If-None-Match", entry.etag);
    }

    if (entry.lastModified > 0) {
        Date refTime = new Date(entry.lastModified);
        // 设置 If-Modified-Since
        headers.put("If-Modified-Since", DateUtils.formatDate(refTime));
    }
}
项目:search    文件:CacheHeaderTest.java   
protected void checkVetoHeaders(HttpResponse response, boolean checkExpires) throws Exception {
  Header head = response.getFirstHeader("Cache-Control");
  assertNotNull("We got no Cache-Control header", head);
  assertTrue("We got no no-cache in the Cache-Control header ["+head+"]", head.getValue().contains("no-cache"));
  assertTrue("We got no no-store in the Cache-Control header ["+head+"]", head.getValue().contains("no-store"));

  head = response.getFirstHeader("Pragma");
  assertNotNull("We got no Pragma header", head);
  assertEquals("no-cache", head.getValue());

  if (checkExpires) {
    head = response.getFirstHeader("Expires");
    assertNotNull("We got no Expires header:" + Arrays.asList(response.getAllHeaders()), head);
    Date d = DateUtils.parseDate(head.getValue());
    assertTrue("We got no Expires header far in the past", System
        .currentTimeMillis()
        - d.getTime() > 100000);
  }
}
项目:NYBC    文件:CacheHeaderTest.java   
protected void checkVetoHeaders(HttpResponse response, boolean checkExpires) throws Exception {
  Header head = response.getFirstHeader("Cache-Control");
  assertNotNull("We got no Cache-Control header", head);
  assertTrue("We got no no-cache in the Cache-Control header ["+head+"]", head.getValue().contains("no-cache"));
  assertTrue("We got no no-store in the Cache-Control header ["+head+"]", head.getValue().contains("no-store"));

  head = response.getFirstHeader("Pragma");
  assertNotNull("We got no Pragma header", head);
  assertEquals("no-cache", head.getValue());

  if (checkExpires) {
    head = response.getFirstHeader("Expires");
    assertNotNull("We got no Expires header:" + Arrays.asList(response.getAllHeaders()), head);
    Date d = DateUtils.parseDate(head.getValue());
    assertTrue("We got no Expires header far in the past", System
        .currentTimeMillis()
        - d.getTime() > 100000);
  }
}
项目:search-core    文件:CacheHeaderTest.java   
protected void checkVetoHeaders(HttpResponse response, boolean checkExpires) throws Exception {
  Header head = response.getFirstHeader("Cache-Control");
  assertNotNull("We got no Cache-Control header", head);
  assertTrue("We got no no-cache in the Cache-Control header ["+head+"]", head.getValue().contains("no-cache"));
  assertTrue("We got no no-store in the Cache-Control header ["+head+"]", head.getValue().contains("no-store"));

  head = response.getFirstHeader("Pragma");
  assertNotNull("We got no Pragma header", head);
  assertEquals("no-cache", head.getValue());

  if (checkExpires) {
    head = response.getFirstHeader("Expires");
    assertNotNull("We got no Expires header:" + Arrays.asList(response.getAllHeaders()), head);
    Date d = DateUtils.parseDate(head.getValue());
    assertTrue("We got no Expires header far in the past", System
        .currentTimeMillis()
        - d.getTime() > 100000);
  }
}
项目:apigee-android-sdk    文件:CacheEntryUpdater.java   
private boolean entryDateHeaderNewerThenResponse(HttpCacheEntry entry,
        HttpResponse response) {
    try {
        Date entryDate = DateUtils.parseDate(entry.getFirstHeader(
                HTTP.DATE_HEADER).getValue());
        Date responseDate = DateUtils.parseDate(response.getFirstHeader(
                HTTP.DATE_HEADER).getValue());

        if (!entryDate.after(responseDate)) {
            return false;
        }
    } catch (DateParseException e) {
        return false;
    }

    return true;
}
项目:apigee-android-sdk    文件:CachingHttpClient.java   
private boolean alreadyHaveNewerCacheEntry(HttpHost target,
        HttpRequest request, HttpResponse backendResponse)
        throws IOException {
    HttpCacheEntry existing = null;
    try {
        existing = responseCache.getCacheEntry(target, request);
    } catch (IOException ioe) {
        // nop
    }
    if (existing == null)
        return false;
    Header entryDateHeader = existing.getFirstHeader("Date");
    if (entryDateHeader == null)
        return false;
    Header responseDateHeader = backendResponse.getFirstHeader("Date");
    if (responseDateHeader == null)
        return false;
    try {
        Date entryDate = DateUtils.parseDate(entryDateHeader.getValue());
        Date responseDate = DateUtils.parseDate(responseDateHeader
                .getValue());
        return responseDate.before(entryDate);
    } catch (DateParseException e) {
    }
    return false;
}
项目:GitHub    文件:HttpHeaderParser.java   
/**
 * 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 DateUtils.parseDate(dateStr).getTime();
    } catch (DateParseException e) {
        // Date in invalid format, fallback to 0
        return 0;
    }
}
项目:GitHub    文件:BasicNetwork.java   
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.lastModified > 0) {
        Date refTime = new Date(entry.lastModified);
        headers.put("If-Modified-Since", DateUtils.formatDate(refTime));
    }
}
项目:GitHub    文件:HttpHeaderParser.java   
/**
 * 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 DateUtils.parseDate(dateStr).getTime();
    } catch (DateParseException e) {
        // Date in invalid format, fallback to 0
        return 0;
    }
}
项目:GitHub    文件:BasicNetwork.java   
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.lastModified > 0) {
        Date refTime = new Date(entry.lastModified);
        headers.put("If-Modified-Since", DateUtils.formatDate(refTime));
    }
}
项目:publicProject    文件:HttpHeaderParser.java   
/**
 * 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 DateUtils.parseDate(dateStr).getTime();
    } catch (DateParseException e) {
        // Date in invalid format, fallback to 0
        return 0;
    }
}
项目:publicProject    文件:BasicNetwork.java   
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.lastModified > 0) {
        Date refTime = new Date(entry.lastModified);
        headers.put("If-Modified-Since", DateUtils.formatDate(refTime));
    }
}
项目:airgram    文件:HttpHeaderParser.java   
/**
 * 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 DateUtils.parseDate(dateStr).getTime();
    } catch (DateParseException e) {
        // Date in invalid format, fallback to 0
        return 0;
    }
}
项目:airgram    文件:BasicNetwork.java   
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.lastModified > 0) {
        Date refTime = new Date(entry.lastModified);
        headers.put("If-Modified-Since", DateUtils.formatDate(refTime));
    }
}
项目:Codeforces    文件:HttpHeaderParser.java   
/**
 * 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 DateUtils.parseDate(dateStr).getTime();
    } catch (DateParseException e) {
        // Date in invalid format, fallback to 0
        return 0;
    }
}
项目:Codeforces    文件:BasicNetwork.java   
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.lastModified > 0) {
        Date refTime = new Date(entry.lastModified);
        headers.put("If-Modified-Since", DateUtils.formatDate(refTime));
    }
}
项目:GeekZone    文件:HttpHeaderParser.java   
/**
 * 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 DateUtils.parseDate(dateStr).getTime();
    } catch (DateParseException e) {
        // Date in invalid format, fallback to 0
        return 0;
    }
}
项目:GeekZone    文件:BasicNetwork.java   
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.lastModified > 0) {
        Date refTime = new Date(entry.lastModified);
        headers.put("If-Modified-Since", DateUtils.formatDate(refTime));
    }
}
项目:iosched-reader    文件:HttpHeaderParser.java   
/**
 * 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 DateUtils.parseDate(dateStr).getTime();
    } catch (DateParseException e) {
        // Date in invalid format, fallback to 0
        return 0;
    }
}
项目:iosched-reader    文件:BasicNetwork.java   
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", DateUtils.formatDate(refTime));
    }
}
项目:PlusGram    文件:HttpHeaderParser.java   
/**
 * 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 DateUtils.parseDate(dateStr).getTime();
    } catch (DateParseException e) {
        // Date in invalid format, fallback to 0
        return 0;
    }
}
项目:PlusGram    文件:BasicNetwork.java   
private void addCacheHeaders(Map<String, String> headers, 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.lastModified > 0) {
        Date refTime = new Date(entry.lastModified);
        headers.put("If-Modified-Since", DateUtils.formatDate(refTime));
    }
}
项目:boohee_v5.6    文件:HttpHeaderParser.java   
public static long parseDateAsEpoch(String dateStr) {
    try {
        return DateUtils.parseDate(dateStr).getTime();
    } catch (DateParseException e) {
        return 0;
    }
}
项目:boohee_v5.6    文件:BasicNetwork.java   
private void addCacheHeaders(Map<String, String> headers, Entry entry) {
    if (entry != null) {
        if (entry.etag != null) {
            headers.put("If-None-Match", entry.etag);
        }
        if (entry.lastModified > 0) {
            headers.put("If-Modified-Since", DateUtils.formatDate(new Date(entry.lastModified)));
        }
    }
}
项目:EsperantoRadio    文件:DrBasicNetwork.java   
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", DateUtils.formatDate(refTime));
  }
}
项目:VoV    文件:HttpHeaderParser.java   
/**
 * 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 DateUtils.parseDate(dateStr).getTime();
    } catch (DateParseException e) {
        // Date in invalid format, fallback to 0
        return 0;
    }
}
项目:VoV    文件:BasicNetwork.java   
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.lastModified > 0) {
        Date refTime = new Date(entry.lastModified);
        headers.put("If-Modified-Since", DateUtils.formatDate(refTime));
    }
}
项目:core-http    文件:BasicNetwork.java   
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.lastModified > 0) {
        Date refTime = new Date(entry.lastModified);
        headers.put("If-Modified-Since", DateUtils.formatDate(refTime));
    }
}
项目:Android-Application-ZJB    文件:BaseNetwork.java   
protected void addCacheHeaders(Map<String, String> headers, Cache.Entry entry) {
    if (entry != null) {
        if (entry.etag != null) {
            headers.put("If-None-Match", entry.etag);
        }
        if (entry.serverDate > 0L) {
            Date refTime = new Date(entry.serverDate);
            headers.put("If-Modified-Since", DateUtils.formatDate(refTime));
        }
    }
}
项目:Android-Application-ZJB    文件:HttpHeaderParser.java   
public static long parseDateAsEpoch(String dateStr) {
    try {
        return DateUtils.parseDate(dateStr).getTime();
    } catch (DateParseException var2) {
        return 0L;
    }
}
项目:smconf-android    文件:HttpHeaderParser.java   
/**
 * 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 DateUtils.parseDate(dateStr).getTime();
    } catch (DateParseException e) {
        // Date in invalid format, fallback to 0
        return 0;
    }
}
项目:smconf-android    文件:BasicNetwork.java   
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", DateUtils.formatDate(refTime));
    }
}
项目:volley    文件:HttpHeaderParser.java   
/**
 * 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 DateUtils.parseDate(dateStr).getTime();
    } catch (DateParseException e) {
        // Date in invalid format, fallback to 0
        return 0;
    }
}
项目:volley    文件:BasicNetwork.java   
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.lastModified > 0) {
        Date refTime = new Date(entry.lastModified);
        headers.put("If-Modified-Since", DateUtils.formatDate(refTime));
    }
}
项目:MeifuGO    文件:HttpHeaderParser.java   
/**
 * 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 DateUtils.parseDate(dateStr).getTime();
    } catch (DateParseException e) {
        // Date in invalid format, fallback to 0
        return 0;
    }
}