org.apache.http.impl.cookie.DateUtils Java Examples
The following examples show how to use
org.apache.http.impl.cookie.DateUtils.
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: CachingHttpClient.java From apigee-android-sdk with Apache License 2.0 | 6 votes |
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; }
Example #2
Source File: BasicNetwork.java From SaveVolley with Apache License 2.0 | 6 votes |
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)); } }
Example #3
Source File: CacheHeaderTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@SuppressForbidden(reason = "Needs currentTimeMillis to check against expiry headers from Solr") 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); } }
Example #4
Source File: CacheEntryUpdater.java From apigee-android-sdk with Apache License 2.0 | 6 votes |
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; }
Example #5
Source File: HttpHeaderParser.java From FeedListViewDemo with MIT License | 5 votes |
/** * 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; } }
Example #6
Source File: HttpHeaderParser.java From android_tv_metro with Apache License 2.0 | 5 votes |
/** * 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; } }
Example #7
Source File: BasicNetwork.java From barterli_android with Apache License 2.0 | 5 votes |
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)); } }
Example #8
Source File: HttpHeaderParser.java From barterli_android with Apache License 2.0 | 5 votes |
/** * 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; } }
Example #9
Source File: BasicNetwork.java From android_tv_metro with Apache License 2.0 | 5 votes |
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)); } }
Example #10
Source File: HttpHeaderParser.java From WayHoo with Apache License 2.0 | 5 votes |
/** * 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; } }
Example #11
Source File: CacheValidityPolicy.java From apigee-android-sdk with Apache License 2.0 | 5 votes |
protected Date getDateValue(final HttpCacheEntry entry) { Header dateHdr = entry.getFirstHeader(HTTP.DATE_HEADER); if (dateHdr == null) return null; try { return DateUtils.parseDate(dateHdr.getValue()); } catch (DateParseException dpe) { // ignore malformed date } return null; }
Example #12
Source File: CacheValidityPolicy.java From apigee-android-sdk with Apache License 2.0 | 5 votes |
protected Date getLastModifiedValue(final HttpCacheEntry entry) { Header dateHdr = entry.getFirstHeader(HeaderConstants.LAST_MODIFIED); if (dateHdr == null) return null; try { return DateUtils.parseDate(dateHdr.getValue()); } catch (DateParseException dpe) { // ignore malformed date } return null; }
Example #13
Source File: CacheValidityPolicy.java From apigee-android-sdk with Apache License 2.0 | 5 votes |
protected Date getExpirationDate(final HttpCacheEntry entry) { Header expiresHeader = entry.getFirstHeader(HeaderConstants.EXPIRES); if (expiresHeader == null) return null; try { return DateUtils.parseDate(expiresHeader.getValue()); } catch (DateParseException dpe) { // malformed expires header } return null; }
Example #14
Source File: CachedResponseSuitabilityChecker.java From apigee-android-sdk with Apache License 2.0 | 5 votes |
private boolean hasValidDateField(HttpRequest request, String headerName) { for (Header h : request.getHeaders(headerName)) { try { DateUtils.parseDate(h.getValue()); return true; } catch (DateParseException dpe) { // ignore malformed dates } } return false; }
Example #15
Source File: ResponseProtocolCompliance.java From apigee-android-sdk with Apache License 2.0 | 5 votes |
private void ensure206ContainsDateHeader(HttpResponse response) { if (response.getFirstHeader(HTTP.DATE_HEADER) == null) { response.addHeader(HTTP.DATE_HEADER, DateUtils.formatDate(new Date())); } }
Example #16
Source File: WarningValue.java From apigee-android-sdk with Apache License 2.0 | 5 votes |
protected void consumeWarnDate() { int curr = offs; Matcher m = WARN_DATE_PATTERN.matcher(src.substring(offs)); if (!m.lookingAt()) parseError(); offs += m.end(); try { warnDate = DateUtils.parseDate(src.substring(curr + 1, offs - 1)); } catch (DateParseException e) { throw new IllegalStateException("couldn't parse a parseable date"); } }
Example #17
Source File: BasicNetwork.java From CrossBow with Apache License 2.0 | 5 votes |
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)); } }
Example #18
Source File: BasicNetwork.java From FeedListViewDemo with MIT License | 5 votes |
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)); } }
Example #19
Source File: HttpResponseResource.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public long getLastModified() { Header responseHeader = response.getFirstHeader("last-modified"); if (responseHeader == null) { return 0; } try { return DateUtils.parseDate(responseHeader.getValue()).getTime(); } catch (Exception e) { return 0; } }
Example #20
Source File: BasicNetwork.java From okulus with Apache License 2.0 | 5 votes |
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)); } }
Example #21
Source File: HttpHeaderParser.java From okulus with Apache License 2.0 | 5 votes |
/** * 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; } }
Example #22
Source File: BasicNetwork.java From jus with Apache License 2.0 | 5 votes |
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)); } }
Example #23
Source File: HttpHeaderParser.java From jus with Apache License 2.0 | 5 votes |
/** * 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; } }
Example #24
Source File: TestBundleHttpStorage.java From thym with Eclipse Public License 1.0 | 5 votes |
private HttpCacheEntry makeHttpCacheEntry() { final Date now = new Date(); final StatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"); final Header[] headers = { new BasicHeader("Date", DateUtils.formatDate(now)), new BasicHeader("Server", "MockServer/1.0") }; final Resource resource = new HeapResource(new byte[0]); HttpCacheEntry entry = new HttpCacheEntry(now, now, statusLine, headers, resource); return entry; }
Example #25
Source File: BasicNetwork.java From volley with Apache License 2.0 | 5 votes |
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)); } }
Example #26
Source File: HttpHeaderParser.java From DaVinci with Apache License 2.0 | 5 votes |
/** * 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; } }
Example #27
Source File: HttpHeaderParser.java From volley with Apache License 2.0 | 5 votes |
/** * 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; } }
Example #28
Source File: BasicNetwork.java From volley_demo with Apache License 2.0 | 5 votes |
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)); } }
Example #29
Source File: HttpHeaderParser.java From volley_demo with Apache License 2.0 | 5 votes |
/** * 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; } }
Example #30
Source File: BasicNetwork.java From DaVinci with Apache License 2.0 | 5 votes |
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)); } }