Skip to content

Commit

Permalink
fixes to usage of no-cache: use and recognize also the no-store
Browse files Browse the repository at this point in the history
directive
  • Loading branch information
Orbiter committed Dec 19, 2014
1 parent c9c700b commit 2868353
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion htroot/NetworkPicture.java
Expand Up @@ -135,7 +135,7 @@ public static EncodedImage respond(
env.getConfig(SwitchboardConstants.NETWORK_NAME, "unspecified"),
env.getConfig("network.unit.description", "unspecified"),
Long.parseLong(bgcolor, 16),
cyc), "png");
cyc), "png", false);
lastAccessSeconds = System.currentTimeMillis() / 1000;

sync.release();
Expand Down
22 changes: 11 additions & 11 deletions source/net/yacy/crawler/retrieval/Response.java
Expand Up @@ -354,7 +354,7 @@ public String shallStoreCacheForProxy() {
// if we have a pragma non-cache, we don't cache. usually if this is wanted from
// the server, it makes sense
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
// we do not care about expires, because at the time this is called the data is
Expand Down Expand Up @@ -443,12 +443,12 @@ public boolean isFreshForProxy() {

// if the client requests a un-cached copy of the resource ...
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);
if (cacheControl != null) {
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
Expand Down Expand Up @@ -487,7 +487,7 @@ public boolean isFreshForProxy() {
// because they cannot exist since they are not written to the cache.
// So this IF should always fail..
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:
// http://www.web-caching.com/cacheability.html
Expand Down Expand Up @@ -529,9 +529,9 @@ public boolean isFreshForProxy() {
// the cache-control has many value options.
if (cacheControl != null) {
cacheControl = cacheControl.trim().toUpperCase();
if (cacheControl.startsWith("PRIVATE") ||
cacheControl.startsWith("NO-CACHE") ||
cacheControl.startsWith("NO-STORE")) {
if (cacheControl.contains("PRIVATE") ||
cacheControl.contains("NO-CACHE") ||
cacheControl.contains("NO-STORE")) {
// easy case
return false;
// } else if (cacheControl.startsWith("PUBLIC")) {
Expand Down Expand Up @@ -640,7 +640,7 @@ public final String shallIndexCacheForProxy() {

// -pragma in cached response
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)";
}

Expand Down Expand Up @@ -672,9 +672,9 @@ public final String shallIndexCacheForProxy() {
"private", "no-cache", "no-store" -- cannot be indexed
"max-age=<delta-seconds>" -- stale/fresh dependent on date
*/
if (cacheControl.startsWith("PRIVATE") ||
cacheControl.startsWith("NO-CACHE") ||
cacheControl.startsWith("NO-STORE")) {
if (cacheControl.contains("PRIVATE") ||
cacheControl.contains("NO-CACHE") ||
cacheControl.contains("NO-STORE")) {
// easy case
return "Stale_(denied_by_cache-control=" + cacheControl + ")";
// } else if (cacheControl.startsWith("PUBLIC")) {
Expand Down
2 changes: 1 addition & 1 deletion source/net/yacy/http/servlets/SolrSelectServlet.java
Expand Up @@ -241,7 +241,7 @@ public void service(ServletRequest request, ServletResponse response) throws IOE
rsp = ((EmbeddedSolrConnector) connector).query(req);

// prepare response
hresponse.setHeader("Cache-Control", "no-cache");
hresponse.setHeader("Cache-Control", "no-cache, no-store");
HttpCacheHeaderUtil.checkHttpCachingVeto(rsp, hresponse, reqMethod);

// check error
Expand Down
6 changes: 4 additions & 2 deletions source/net/yacy/http/servlets/YaCyDefaultServlet.java
Expand Up @@ -480,7 +480,7 @@ protected void sendDirectory(HttpServletRequest request,
byte[] data = dir.getBytes("UTF-8");
response.setContentType(TEXT_HTML_UTF_8.asString());
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.LAST_MODIFIED, resource.lastModified());
response.getOutputStream().write(data);
Expand Down Expand Up @@ -790,7 +790,6 @@ protected void handleTemplate(String target, HttpServletRequest request, HttpSe
response.setDateHeader(HeaderFramework.EXPIRES, now + 1000); // expires in 1 seconds (reduce heavy image creation load)
} else {
response.setDateHeader(HeaderFramework.EXPIRES, now); // expires now
response.setHeader(HeaderFramework.CACHE_CONTROL, "no-cache");
}

if ((targetClass != null)) {
Expand Down Expand Up @@ -843,6 +842,9 @@ protected void handleTemplate(String target, HttpServletRequest request, HttpSe
} else if (tmp instanceof EncodedImage) {
final EncodedImage yp = (EncodedImage) tmp;
result = yp.getImage();
if (yp.isStatic()) {
response.setDateHeader(HeaderFramework.EXPIRES, now + 600000); // expires in ten minutes
}
} else if (tmp instanceof Image) {
final Image i = (Image) tmp;

Expand Down
2 changes: 1 addition & 1 deletion source/net/yacy/peers/SeedDB.java
Expand Up @@ -866,7 +866,7 @@ private static Iterator<String> downloadSeedFile(final DigestURL seedURL) throws
// Configure http headers
final RequestHeader reqHeader = new RequestHeader();
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);

final HTTPClient client = new HTTPClient(ClientIdentification.yacyInternetCrawlerAgent);
Expand Down
2 changes: 1 addition & 1 deletion source/net/yacy/search/Switchboard.java
Expand Up @@ -3766,7 +3766,7 @@ public void run() {
//final long start = System.currentTimeMillis();
final RequestHeader reqHeader = new RequestHeader();
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);
client.setHeader(reqHeader.entrySet());

Expand Down
2 changes: 1 addition & 1 deletion source/net/yacy/server/http/HTTPDemon.java
Expand Up @@ -228,7 +228,7 @@ private static final void sendRespondError(
header.put(HeaderFramework.DATE, systemDate);
header.put(HeaderFramework.CONTENT_TYPE, "text/html");
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);

if (! method.equals(HeaderFramework.METHOD_HEAD)) {
Expand Down

0 comments on commit 2868353

Please sign in to comment.