use of com.google.gerrit.extensions.restapi.ETagView in project gerrit by GerritCodeReview.
the class RestApiServlet method notModified.
@SuppressWarnings({ "unchecked", "rawtypes" })
private static boolean notModified(HttpServletRequest req, RestResource rsrc, RestView<RestResource> view) {
if (!isRead(req)) {
return false;
}
if (view instanceof ETagView) {
String have = req.getHeader(HttpHeaders.IF_NONE_MATCH);
if (have != null) {
return have.equals(((ETagView) view).getETag(rsrc));
}
}
if (rsrc instanceof RestResource.HasETag) {
String have = req.getHeader(HttpHeaders.IF_NONE_MATCH);
if (have != null) {
return have.equals(((RestResource.HasETag) rsrc).getETag());
}
}
if (rsrc instanceof RestResource.HasLastModified) {
Timestamp m = ((RestResource.HasLastModified) rsrc).getLastModified();
long d = req.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
// HTTP times are in seconds, database may have millisecond precision.
return d / 1000L == m.getTime() / 1000L;
}
return false;
}
use of com.google.gerrit.extensions.restapi.ETagView in project gerrit by GerritCodeReview.
the class RestApiServlet method addResourceStateHeaders.
private void addResourceStateHeaders(HttpServletRequest req, HttpServletResponse res, TraceContext traceContext, ViewData viewData, RestResource rsrc) {
RestView<RestResource> view = viewData.view;
if (view instanceof ETagView) {
String eTag = getEtagWithRetry(req, traceContext, viewData, (ETagView<RestResource>) view, rsrc);
res.setHeader(HttpHeaders.ETAG, eTag);
} else if (rsrc instanceof RestResource.HasETag) {
String eTag = getEtagWithRetry(req, traceContext, (RestResource.HasETag) rsrc);
if (!Strings.isNullOrEmpty(eTag)) {
res.setHeader(HttpHeaders.ETAG, eTag);
}
}
if (rsrc instanceof RestResource.HasLastModified) {
res.setDateHeader(HttpHeaders.LAST_MODIFIED, ((RestResource.HasLastModified) rsrc).getLastModified().getTime());
}
}
use of com.google.gerrit.extensions.restapi.ETagView in project gerrit by GerritCodeReview.
the class RestApiServlet method notModified.
private boolean notModified(HttpServletRequest req, TraceContext traceContext, ViewData viewData, RestResource rsrc) {
if (!isRead(req)) {
return false;
}
RestView<RestResource> view = viewData.view;
if (view instanceof ETagView) {
String have = req.getHeader(HttpHeaders.IF_NONE_MATCH);
if (have != null) {
String eTag = getEtagWithRetry(req, traceContext, viewData, (ETagView<RestResource>) view, rsrc);
return have.equals(eTag);
}
}
if (rsrc instanceof RestResource.HasETag) {
String have = req.getHeader(HttpHeaders.IF_NONE_MATCH);
if (!Strings.isNullOrEmpty(have)) {
String eTag = getEtagWithRetry(req, traceContext, (RestResource.HasETag) rsrc);
return have.equals(eTag);
}
}
if (rsrc instanceof RestResource.HasLastModified) {
Timestamp m = ((RestResource.HasLastModified) rsrc).getLastModified();
long d = req.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
// HTTP times are in seconds, database may have millisecond precision.
return d / 1000L == m.getTime() / 1000L;
}
return false;
}
Aggregations