]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/Server.cc
Merged from trunk 13199.
[thirdparty/squid.git] / src / Server.cc
index 295bb5509c8f879dc2dbbf1396b6028ca9f31639..8438cd29786ef00615c34d8e3af06c4fe251e33f 100644 (file)
@@ -31,6 +31,7 @@
  */
 
 #include "squid.h"
+#include "acl/FilledChecklist.h"
 #include "acl/Gadgets.h"
 #include "base/TextException.h"
 #include "comm/Connection.h"
@@ -43,6 +44,7 @@
 #include "HttpReply.h"
 #include "HttpRequest.h"
 #include "Server.h"
+#include "SquidConfig.h"
 #include "SquidTime.h"
 #include "StatCounters.h"
 #include "Store.h"
@@ -54,7 +56,6 @@
 #include "adaptation/Answer.h"
 #include "adaptation/Iterator.h"
 #include "base/AsyncCall.h"
-#include "SquidConfig.h"
 #endif
 
 // implemented in client_side_reply.cc until sides have a common parent
@@ -174,6 +175,8 @@ ServerStateData::setFinalReply(HttpReply *rep)
     // give entry the reply because haveParsedReplyHeaders() expects it there
     entry->replaceHttpReply(theFinalReply, false); // but do not write yet
     haveParsedReplyHeaders(); // update the entry/reply (e.g., set timestamps)
+    if (!EBIT_TEST(entry->flags, RELEASE_REQUEST) && blockCaching())
+        entry->release();
     entry->startWriting(); // write the updated entry to store
 
     return theFinalReply;
@@ -533,6 +536,24 @@ ServerStateData::haveParsedReplyHeaders()
     currentOffset = partial ? theFinalReply->content_range->spec.offset : 0;
 }
 
+/// whether to prevent caching of an otherwise cachable response
+bool
+ServerStateData::blockCaching()
+{
+    if (const Acl::Tree *acl = Config.accessList.storeMiss) {
+        // This relatively expensive check is not in StoreEntry::checkCachable:
+        // That method lacks HttpRequest and may be called too many times.
+        ACLFilledChecklist ch(acl, originalRequest(), NULL);
+        ch.reply = const_cast<HttpReply*>(entry->getReply()); // ACLFilledChecklist API bug
+        HTTPMSGLOCK(ch.reply);
+        if (ch.fastCheck() != ACCESS_ALLOWED) { // when in doubt, block
+            debugs(20, 3, "store_miss prohibits caching");
+            return true;
+        }
+    }
+    return false;
+}
+
 HttpRequest *
 ServerStateData::originalRequest()
 {