]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 4169: HIT marked as MISS when If-None-Match does not match
authorGarri Djavadyan <garryd@comnet.uz>
Wed, 7 Dec 2016 19:39:21 +0000 (08:39 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 7 Dec 2016 19:39:21 +0000 (08:39 +1300)
src/LogTags.cc
src/LogTags.h
src/client_side.cc
src/client_side_reply.cc

index 3e43b9a85010ca20b1f9414040ada49dc5a42bbb..aac4a3c673934d4bc3d199fa79f554e2081c57aa 100644 (file)
@@ -21,6 +21,7 @@ const char * LogTags::Str_[] = {
     "TCP_REFRESH",
     "TCP_CLIENT_REFRESH_MISS",
     "TCP_IMS_HIT",
+    "TCP_INM_HIT",
     "TCP_SWAPFAIL_MISS",
     "TCP_NEGATIVE_HIT",
     "TCP_MEM_HIT",
@@ -73,6 +74,7 @@ LogTags::isTcpHit() const
     return
         (oldType == LOG_TCP_HIT) ||
         (oldType == LOG_TCP_IMS_HIT) ||
+        (oldType == LOG_TCP_INM_HIT) ||
         (oldType == LOG_TCP_REFRESH_FAIL_OLD) ||
         (oldType == LOG_TCP_REFRESH_UNMODIFIED) ||
         (oldType == LOG_TCP_NEGATIVE_HIT) ||
index c31082e17360718b15aa94682c664c943ff9a8e5..a45c898a3a00fbd50db6aac9d7b8c1855eaa2997 100644 (file)
@@ -28,6 +28,7 @@ typedef enum {
     LOG_TCP_REFRESH,            // refresh from origin started, but still pending
     LOG_TCP_CLIENT_REFRESH_MISS,
     LOG_TCP_IMS_HIT,
+    LOG_TCP_INM_HIT,
     LOG_TCP_SWAPFAIL_MISS,
     LOG_TCP_NEGATIVE_HIT,
     LOG_TCP_MEM_HIT,
index dc4d885549aafa80971ccfcfcc500531f35f475e..5263a810c9a5524fc062accf9cfdd41ba68d4141 100644 (file)
@@ -229,6 +229,7 @@ clientUpdateStatHistCounters(const LogTags &logType, int svc_time)
         statCounter.client_http.nearHitSvcTime.count(svc_time);
         break;
 
+    case LOG_TCP_INM_HIT:
     case LOG_TCP_IMS_HIT:
         statCounter.client_http.nearMissSvcTime.count(svc_time);
         break;
index 3459f3030f3a97d8c08d1ab4b987ca75f0139646..af89e2354bb28bbfd5f6865a453bf32c9d079ce1 100644 (file)
@@ -796,40 +796,27 @@ clientReplyContext::processConditional(StoreIOBuffer &result)
         return true;
     }
 
-    bool matchedIfNoneMatch = false;
     if (r.header.has(Http::HdrType::IF_NONE_MATCH)) {
-        if (!e->hasIfNoneMatchEtag(r)) {
-            // RFC 2616: ignore IMS if If-None-Match did not match
-            r.flags.ims = false;
-            r.ims = -1;
-            r.imslen = 0;
-            r.header.delById(Http::HdrType::IF_MODIFIED_SINCE);
-            http->logType = LOG_TCP_MISS;
-            sendMoreData(result);
-            return true;
-        }
+        // RFC 7232: If-None-Match recipient MUST ignore IMS
+        r.flags.ims = false;
+        r.ims = -1;
+        r.imslen = 0;
+        r.header.delById(Http::HdrType::IF_MODIFIED_SINCE);
 
-        if (!r.flags.ims) {
-            // RFC 2616: if If-None-Match matched and there is no IMS,
-            // reply with 304 Not Modified or 412 Precondition Failed
+        if (e->hasIfNoneMatchEtag(r)) {
             sendNotModifiedOrPreconditionFailedError();
             return true;
         }
 
-        // otherwise check IMS below to decide if we reply with 304 or 412
-        matchedIfNoneMatch = true;
+        // None-Match is true (no ETag matched); treat as an unconditional hit
+        return false;
     }
 
     if (r.flags.ims) {
         // handle If-Modified-Since requests from the client
         if (e->modifiedSince(r.ims, r.imslen)) {
-            http->logType = LOG_TCP_IMS_HIT;
-            sendMoreData(result);
-
-        } else if (matchedIfNoneMatch) {
-            // If-None-Match matched, reply with 304 Not Modified or
-            // 412 Precondition Failed
-            sendNotModifiedOrPreconditionFailedError();
+           // Modified-Since is true; treat as an unconditional hit
+           return false;
 
         } else {
             // otherwise reply with 304 Not Modified
@@ -1991,7 +1978,12 @@ clientReplyContext::sendNotModified()
     StoreEntry *e = http->storeEntry();
     const time_t timestamp = e->timestamp;
     HttpReply *const temprep = e->getReply()->make304();
-    http->logType = LOG_TCP_IMS_HIT;
+    // log as TCP_INM_HIT if code 304 generated for
+    // If-None-Match request
+    if (!http->request->flags.ims)
+        http->logType = LOG_TCP_INM_HIT;
+    else
+        http->logType = LOG_TCP_IMS_HIT;
     removeClientStoreReference(&sc, http);
     createStoreEntry(http->request->method, RequestFlags());
     e = http->storeEntry();