in plugins/rest/src/main/java/org/apache/struts2/rest/DefaultHttpHeaders.java [93:148]
public String apply(HttpServletRequest request, HttpServletResponse response, Object target) {
if (disableCaching) {
response.setHeader("Cache-Control", "no-cache");
}
if (lastModified != null) {
response.setDateHeader("Last-Modified", lastModified.getTime());
}
if (etag == null && !noETag && target != null) {
etag = String.valueOf(target.hashCode());
}
if (etag != null) {
response.setHeader("ETag", etag.toString());
}
if (locationId != null) {
String url = request.getRequestURL().toString();
int lastSlash = url.lastIndexOf("/");
int lastDot = url.lastIndexOf(".");
if (lastDot > lastSlash && lastDot > -1) {
url = url.substring(0, lastDot) + "/" + locationId + url.substring(lastDot);
} else {
url += "/" + locationId;
}
response.setHeader("Location", url);
status = SC_CREATED;
} else if (location != null) {
response.setHeader("Location", location);
status = SC_CREATED;
}
if (status == SC_OK && !disableCaching) {
boolean etagNotChanged = false;
boolean lastModifiedNotChanged = false;
String reqETag = request.getHeader("If-None-Match");
if (etag != null) {
if (etag.equals(reqETag)) {
etagNotChanged = true;
}
}
String headerIfModifiedSince = request.getHeader("If-Modified-Since");
if (lastModified != null && headerIfModifiedSince != null) {
lastModifiedNotChanged = compareIfModifiedSince(headerIfModifiedSince);
}
if ((etagNotChanged && lastModifiedNotChanged) ||
(etagNotChanged && headerIfModifiedSince == null) ||
(lastModifiedNotChanged && reqETag == null)) {
status = SC_NOT_MODIFIED;
}
}
response.setStatus(status);
return resultCode;
}