fixes to usage of no-cache: use and recognize also the no-store

directive
pull/1/head
Michael Peter Christen 10 years ago
parent c9c700b510
commit 28683530cd

@ -135,7 +135,7 @@ public class NetworkPicture {
env.getConfig(SwitchboardConstants.NETWORK_NAME, "unspecified"), env.getConfig(SwitchboardConstants.NETWORK_NAME, "unspecified"),
env.getConfig("network.unit.description", "unspecified"), env.getConfig("network.unit.description", "unspecified"),
Long.parseLong(bgcolor, 16), Long.parseLong(bgcolor, 16),
cyc), "png"); cyc), "png", false);
lastAccessSeconds = System.currentTimeMillis() / 1000; lastAccessSeconds = System.currentTimeMillis() / 1000;
sync.release(); sync.release();

@ -354,7 +354,7 @@ public class Response {
// if we have a pragma non-cache, we don't cache. usually if this is wanted from // if we have a pragma non-cache, we don't cache. usually if this is wanted from
// the server, it makes sense // the server, it makes sense
String cacheControl = this.responseHeader.get(HeaderFramework.PRAGMA); String cacheControl = this.responseHeader.get(HeaderFramework.PRAGMA);
if (cacheControl != null && cacheControl.trim().toUpperCase().equals("NO-CACHE")) { return "controlled_no_cache"; } if (cacheControl != null && cacheControl.trim().toUpperCase().contains("NO-CACHE")) { return "controlled_no_cache"; }
// -expires in response // -expires in response
// we do not care about expires, because at the time this is called the data is // we do not care about expires, because at the time this is called the data is
@ -443,12 +443,12 @@ public class Response {
// if the client requests a un-cached copy of the resource ... // if the client requests a un-cached copy of the resource ...
cacheControl = this.requestHeader.get(HeaderFramework.PRAGMA); cacheControl = this.requestHeader.get(HeaderFramework.PRAGMA);
if (cacheControl != null && cacheControl.trim().toUpperCase().equals("NO-CACHE")) { return false; } if (cacheControl != null && cacheControl.trim().toUpperCase().contains("NO-CACHE")) { return false; }
cacheControl = this.requestHeader.get(HeaderFramework.CACHE_CONTROL); cacheControl = this.requestHeader.get(HeaderFramework.CACHE_CONTROL);
if (cacheControl != null) { if (cacheControl != null) {
cacheControl = cacheControl.trim().toUpperCase(); cacheControl = cacheControl.trim().toUpperCase();
if (cacheControl.startsWith("NO-CACHE") || cacheControl.startsWith("MAX-AGE=0")) { return false; } if (cacheControl.contains("NO-CACHE") || cacheControl.startsWith("MAX-AGE=0")) { return false; }
} }
// -if-modified-since in request // -if-modified-since in request
@ -487,7 +487,7 @@ public class Response {
// because they cannot exist since they are not written to the cache. // because they cannot exist since they are not written to the cache.
// So this IF should always fail.. // So this IF should always fail..
cacheControl = this.responseHeader.get(HeaderFramework.PRAGMA); cacheControl = this.responseHeader.get(HeaderFramework.PRAGMA);
if (cacheControl != null && cacheControl.trim().toUpperCase().equals("NO-CACHE")) { return false; } if (cacheControl != null && cacheControl.trim().toUpperCase().contains("NO-CACHE")) { return false; }
// see for documentation also: // see for documentation also:
// http://www.web-caching.com/cacheability.html // http://www.web-caching.com/cacheability.html
@ -529,9 +529,9 @@ public class Response {
// the cache-control has many value options. // the cache-control has many value options.
if (cacheControl != null) { if (cacheControl != null) {
cacheControl = cacheControl.trim().toUpperCase(); cacheControl = cacheControl.trim().toUpperCase();
if (cacheControl.startsWith("PRIVATE") || if (cacheControl.contains("PRIVATE") ||
cacheControl.startsWith("NO-CACHE") || cacheControl.contains("NO-CACHE") ||
cacheControl.startsWith("NO-STORE")) { cacheControl.contains("NO-STORE")) {
// easy case // easy case
return false; return false;
// } else if (cacheControl.startsWith("PUBLIC")) { // } else if (cacheControl.startsWith("PUBLIC")) {
@ -640,7 +640,7 @@ public class Response {
// -pragma in cached response // -pragma in cached response
if (this.responseHeader.containsKey(HeaderFramework.PRAGMA) && if (this.responseHeader.containsKey(HeaderFramework.PRAGMA) &&
(this.responseHeader.get(HeaderFramework.PRAGMA)).toUpperCase().equals("NO-CACHE")) { (this.responseHeader.get(HeaderFramework.PRAGMA)).toUpperCase().contains("NO-CACHE")) {
return "Denied_(pragma_no_cache)"; return "Denied_(pragma_no_cache)";
} }
@ -672,9 +672,9 @@ public class Response {
"private", "no-cache", "no-store" -- cannot be indexed "private", "no-cache", "no-store" -- cannot be indexed
"max-age=<delta-seconds>" -- stale/fresh dependent on date "max-age=<delta-seconds>" -- stale/fresh dependent on date
*/ */
if (cacheControl.startsWith("PRIVATE") || if (cacheControl.contains("PRIVATE") ||
cacheControl.startsWith("NO-CACHE") || cacheControl.contains("NO-CACHE") ||
cacheControl.startsWith("NO-STORE")) { cacheControl.contains("NO-STORE")) {
// easy case // easy case
return "Stale_(denied_by_cache-control=" + cacheControl + ")"; return "Stale_(denied_by_cache-control=" + cacheControl + ")";
// } else if (cacheControl.startsWith("PUBLIC")) { // } else if (cacheControl.startsWith("PUBLIC")) {

@ -241,7 +241,7 @@ public class SolrSelectServlet extends HttpServlet {
rsp = ((EmbeddedSolrConnector) connector).query(req); rsp = ((EmbeddedSolrConnector) connector).query(req);
// prepare response // prepare response
hresponse.setHeader("Cache-Control", "no-cache"); hresponse.setHeader("Cache-Control", "no-cache, no-store");
HttpCacheHeaderUtil.checkHttpCachingVeto(rsp, hresponse, reqMethod); HttpCacheHeaderUtil.checkHttpCachingVeto(rsp, hresponse, reqMethod);
// check error // check error

@ -480,7 +480,7 @@ public class YaCyDefaultServlet extends HttpServlet {
byte[] data = dir.getBytes("UTF-8"); byte[] data = dir.getBytes("UTF-8");
response.setContentType(TEXT_HTML_UTF_8.asString()); response.setContentType(TEXT_HTML_UTF_8.asString());
response.setContentLength(data.length); response.setContentLength(data.length);
response.setHeader(HeaderFramework.CACHE_CONTROL, "no-cache"); response.setHeader(HeaderFramework.CACHE_CONTROL, "no-cache, no-store");
response.setDateHeader(HeaderFramework.EXPIRES, System.currentTimeMillis() + 10000); // consider that directories are not modified that often response.setDateHeader(HeaderFramework.EXPIRES, System.currentTimeMillis() + 10000); // consider that directories are not modified that often
response.setDateHeader(HeaderFramework.LAST_MODIFIED, resource.lastModified()); response.setDateHeader(HeaderFramework.LAST_MODIFIED, resource.lastModified());
response.getOutputStream().write(data); response.getOutputStream().write(data);
@ -790,7 +790,6 @@ public class YaCyDefaultServlet extends HttpServlet {
response.setDateHeader(HeaderFramework.EXPIRES, now + 1000); // expires in 1 seconds (reduce heavy image creation load) response.setDateHeader(HeaderFramework.EXPIRES, now + 1000); // expires in 1 seconds (reduce heavy image creation load)
} else { } else {
response.setDateHeader(HeaderFramework.EXPIRES, now); // expires now response.setDateHeader(HeaderFramework.EXPIRES, now); // expires now
response.setHeader(HeaderFramework.CACHE_CONTROL, "no-cache");
} }
if ((targetClass != null)) { if ((targetClass != null)) {
@ -843,6 +842,9 @@ public class YaCyDefaultServlet extends HttpServlet {
} else if (tmp instanceof EncodedImage) { } else if (tmp instanceof EncodedImage) {
final EncodedImage yp = (EncodedImage) tmp; final EncodedImage yp = (EncodedImage) tmp;
result = yp.getImage(); result = yp.getImage();
if (yp.isStatic()) {
response.setDateHeader(HeaderFramework.EXPIRES, now + 600000); // expires in ten minutes
}
} else if (tmp instanceof Image) { } else if (tmp instanceof Image) {
final Image i = (Image) tmp; final Image i = (Image) tmp;

@ -866,7 +866,7 @@ public final class SeedDB implements AlternativeDomainNames {
// Configure http headers // Configure http headers
final RequestHeader reqHeader = new RequestHeader(); final RequestHeader reqHeader = new RequestHeader();
reqHeader.put(HeaderFramework.PRAGMA, "no-cache"); reqHeader.put(HeaderFramework.PRAGMA, "no-cache");
reqHeader.put(HeaderFramework.CACHE_CONTROL, "no-cache"); // httpc uses HTTP/1.0 is this necessary? reqHeader.put(HeaderFramework.CACHE_CONTROL, "no-cache, no-store"); // httpc uses HTTP/1.0 is this necessary?
reqHeader.put(HeaderFramework.USER_AGENT, ClientIdentification.yacyInternetCrawlerAgent.userAgent); reqHeader.put(HeaderFramework.USER_AGENT, ClientIdentification.yacyInternetCrawlerAgent.userAgent);
final HTTPClient client = new HTTPClient(ClientIdentification.yacyInternetCrawlerAgent); final HTTPClient client = new HTTPClient(ClientIdentification.yacyInternetCrawlerAgent);

@ -3766,7 +3766,7 @@ public final class Switchboard extends serverSwitch {
//final long start = System.currentTimeMillis(); //final long start = System.currentTimeMillis();
final RequestHeader reqHeader = new RequestHeader(); final RequestHeader reqHeader = new RequestHeader();
reqHeader.put(HeaderFramework.PRAGMA, "no-cache"); reqHeader.put(HeaderFramework.PRAGMA, "no-cache");
reqHeader.put(HeaderFramework.CACHE_CONTROL, "no-cache"); reqHeader.put(HeaderFramework.CACHE_CONTROL, "no-cache, no-store");
final HTTPClient client = new HTTPClient(ClientIdentification.yacyInternetCrawlerAgent, timeout); final HTTPClient client = new HTTPClient(ClientIdentification.yacyInternetCrawlerAgent, timeout);
client.setHeader(reqHeader.entrySet()); client.setHeader(reqHeader.entrySet());

@ -228,7 +228,7 @@ public final class HTTPDemon {
header.put(HeaderFramework.DATE, systemDate); header.put(HeaderFramework.DATE, systemDate);
header.put(HeaderFramework.CONTENT_TYPE, "text/html"); header.put(HeaderFramework.CONTENT_TYPE, "text/html");
header.put(HeaderFramework.CONTENT_LENGTH, Integer.toString(result.length)); header.put(HeaderFramework.CONTENT_LENGTH, Integer.toString(result.length));
header.put(HeaderFramework.PRAGMA, "no-cache"); header.put(HeaderFramework.PRAGMA, "no-cache, no-store");
sendRespondHeader(conProp,respond,httpVersion,httpStatusCode,httpStatusText,header); sendRespondHeader(conProp,respond,httpVersion,httpStatusCode,httpStatusText,header);
if (! method.equals(HeaderFramework.METHOD_HEAD)) { if (! method.equals(HeaderFramework.METHOD_HEAD)) {

Loading…
Cancel
Save