List of usage examples for com.google.common.net HttpHeaders IF_NONE_MATCH
String IF_NONE_MATCH
To view the source code for com.google.common.net HttpHeaders IF_NONE_MATCH.
Click Source Link
From source file:com.khannedy.sajikeun.servlet.AssetServlet.java
private boolean isCachedClientSide(HttpServletRequest req, Asset asset) { return asset.getETag().equals(req.getHeader(HttpHeaders.IF_NONE_MATCH)) || (req.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE) >= asset.getLastModified()); }
From source file:org.sonatype.nexus.repository.http.HttpConditions.java
@Nullable private static Predicate<Response> ifNoneMatch(final Request request) { final String match = request.getHeaders().get(HttpHeaders.IF_NONE_MATCH); if (match != null && !"*".equals(match)) { return new Predicate<Response>() { @Override/* w w w. j a v a 2 s . c om*/ public boolean apply(final Response response) { final String etag = response.getHeaders().get(HttpHeaders.ETAG); if (etag != null) { return !match.contains(etag); } return true; } @Override public String toString() { return HttpConditions.class.getSimpleName() + ".ifNoneMatch(" + match + ")"; } }; } return null; }
From source file:net.staticsnow.nexus.repository.apt.internal.proxy.AptProxyFacet.java
private HttpGet buildFetchRequest(Content oldVersion, URI fetchUri) { HttpGet getRequest = new HttpGet(fetchUri); if (oldVersion != null) { DateTime lastModified = oldVersion.getAttributes().get(Content.CONTENT_LAST_MODIFIED, DateTime.class); if (lastModified != null) { getRequest.addHeader(HttpHeaders.IF_MODIFIED_SINCE, DateUtils.formatDate(lastModified.toDate())); }//w w w . ja v a2 s . c om final String etag = oldVersion.getAttributes().get(Content.CONTENT_ETAG, String.class); if (etag != null) { getRequest.addHeader(HttpHeaders.IF_NONE_MATCH, "\"" + etag + "\""); } } return getRequest; }
From source file:org.sonatype.nexus.repository.proxy.ProxyFacetSupport.java
protected Content fetch(String url, Context context, @Nullable Content stale) throws IOException { HttpClient client = httpClient.getHttpClient(); URI uri = config.remoteUrl.resolve(url); HttpRequestBase request = buildFetchHttpRequest(uri, context); if (stale != null) { final DateTime lastModified = stale.getAttributes().get(Content.CONTENT_LAST_MODIFIED, DateTime.class); if (lastModified != null) { request.addHeader(HttpHeaders.IF_MODIFIED_SINCE, DateUtils.formatDate(lastModified.toDate())); }/*from w w w . j a v a2 s .c o m*/ final String etag = stale.getAttributes().get(Content.CONTENT_ETAG, String.class); if (etag != null) { request.addHeader(HttpHeaders.IF_NONE_MATCH, "\"" + etag + "\""); } } log.debug("Fetching: {}", request); HttpResponse response = execute(context, client, request); log.debug("Response: {}", response); StatusLine status = response.getStatusLine(); log.debug("Status: {}", status); final CacheInfo cacheInfo = getCacheController(context).current(); if (status.getStatusCode() == HttpStatus.SC_OK) { HttpEntity entity = response.getEntity(); log.debug("Entity: {}", entity); final Content result = createContent(context, response); result.getAttributes().set(Content.CONTENT_LAST_MODIFIED, extractLastModified(request, response)); result.getAttributes().set(Content.CONTENT_ETAG, extractETag(response)); result.getAttributes().set(CacheInfo.class, cacheInfo); return result; } try { if (status.getStatusCode() == HttpStatus.SC_NOT_MODIFIED) { checkState(stale != null, "Received 304 without conditional GET (bad server?) from %s", uri); indicateVerified(context, stale, cacheInfo); } mayThrowProxyServiceException(response); } finally { HttpClientUtils.closeQuietly(response); } return null; }
From source file:com.github.dirkraft.dropwizard.fileassets.FileAssetServlet.java
private boolean isCachedClientSide(HttpServletRequest req, CachedAsset cachedAsset) { return cachedAsset.getETag().equals(req.getHeader(HttpHeaders.IF_NONE_MATCH)) || (req.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE) >= cachedAsset.getLastModifiedTime()); }
From source file:com.googlesource.gerrit.plugins.xdocs.XDocServlet.java
private static boolean isResourceNotModified(HttpServletRequest req, ResourceKey key, ObjectId revId, ObjectId revIdB) {/*w w w . j av a2s. c o m*/ String receivedETag = req.getHeader(HttpHeaders.IF_NONE_MATCH); if (receivedETag != null) { return receivedETag.equals(computeETag(key.project, revId, key.file, revIdB, key.diffMode)); } return false; }