]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 3379: Combination of If-Match and a Cache Hit result in TCP Connection Failure
authorGarri Djavadyan <garryd@comnet.uz>
Fri, 16 Dec 2016 12:53:23 +0000 (01:53 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 16 Dec 2016 12:53:23 +0000 (01:53 +1300)
src/client_side_reply.cc
src/client_side_reply.h

index 651239446d1d6ba04417f187dc60a65754024327..e70166dc846527cefa60d570eab97b26d5192d29 100644 (file)
@@ -545,6 +545,7 @@ clientReplyContext::cacheHit(StoreIOBuffer result)
        ) {
         http->logType = LOG_TCP_NEGATIVE_HIT;
         sendMoreData(result);
+        return;
     } else if (!http->flags.internal && refreshCheckHTTP(e, r)) {
         debugs(88, 5, "clientCacheHit: in refreshCheck() block");
         /*
@@ -591,25 +592,29 @@ clientReplyContext::cacheHit(StoreIOBuffer result)
             http->logType = LOG_TCP_MISS;
             processMiss();
         }
-    } else if (r->conditional())
-        processConditional(result);
-    else {
-        /*
-         * plain ol' cache hit
-         */
+        return;
+    } else if (r->conditional()) {
+        debugs(88, 5, "conditional HIT");
+        if (processConditional(result))
+            return;
+    }
+
+    /*
+     * plain ol' cache hit
+     */
+    debugs(88, 5, "plain old HIT");
 
 #if USE_DELAY_POOLS
-        if (e->store_status != STORE_OK)
-            http->logType = LOG_TCP_MISS;
-        else
+    if (e->store_status != STORE_OK)
+        http->logType = LOG_TCP_MISS;
+    else
 #endif
-            if (e->mem_status == IN_MEMORY)
-                http->logType = LOG_TCP_MEM_HIT;
-            else if (Config.onoff.offline)
-                http->logType = LOG_TCP_OFFLINE_HIT;
+        if (e->mem_status == IN_MEMORY)
+            http->logType = LOG_TCP_MEM_HIT;
+        else if (Config.onoff.offline)
+            http->logType = LOG_TCP_OFFLINE_HIT;
 
-        sendMoreData(result);
-    }
+    sendMoreData(result);
 }
 
 /**
@@ -708,17 +713,16 @@ clientReplyContext::processOnlyIfCachedMiss()
 }
 
 /// process conditional request from client
-void
+bool
 clientReplyContext::processConditional(StoreIOBuffer &result)
 {
     StoreEntry *const e = http->storeEntry();
 
     if (e->getReply()->sline.status() != Http::scOkay) {
-        debugs(88, 4, "clientReplyContext::processConditional: Reply code " <<
-               e->getReply()->sline.status() << " != 200");
+        debugs(88, 4, "Reply code " << e->getReply()->sline.status() << " != 200");
         http->logType = LOG_TCP_MISS;
         processMiss();
-        return;
+        return true;
     }
 
     HttpRequest &r = *http->request;
@@ -726,7 +730,7 @@ clientReplyContext::processConditional(StoreIOBuffer &result)
     if (r.header.has(HDR_IF_MATCH) && !e->hasIfMatchEtag(r)) {
         // RFC 2616: reply with 412 Precondition Failed if If-Match did not match
         sendPreconditionFailedError();
-        return;
+        return true;
     }
 
     bool matchedIfNoneMatch = false;
@@ -739,14 +743,14 @@ clientReplyContext::processConditional(StoreIOBuffer &result)
             r.header.delById(HDR_IF_MODIFIED_SINCE);
             http->logType = LOG_TCP_MISS;
             sendMoreData(result);
-            return;
+            return true;
         }
 
         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
             sendNotModifiedOrPreconditionFailedError();
-            return;
+            return true;
         }
 
         // otherwise check IMS below to decide if we reply with 304 or 412
@@ -758,19 +762,20 @@ clientReplyContext::processConditional(StoreIOBuffer &result)
         if (e->modifiedSince(&r)) {
             http->logType = LOG_TCP_IMS_HIT;
             sendMoreData(result);
-            return;
-        }
 
-        if (matchedIfNoneMatch) {
+        } else if (matchedIfNoneMatch) {
             // If-None-Match matched, reply with 304 Not Modified or
             // 412 Precondition Failed
             sendNotModifiedOrPreconditionFailedError();
-            return;
-        }
 
-        // otherwise reply with 304 Not Modified
-        sendNotModified();
+        } else {
+            // otherwise reply with 304 Not Modified
+            sendNotModified();
+        }
+        return true;
     }
+
+    return false;
 }
 
 void
index 7b294ab6bb093946f41c0197e36019a548c0b644..4fbb04ca43848d7ce8b11854c0490e54d2c056b0 100644 (file)
@@ -133,7 +133,7 @@ private:
     bool alwaysAllowResponse(Http::StatusCode sline) const;
     int checkTransferDone();
     void processOnlyIfCachedMiss();
-    void processConditional(StoreIOBuffer &result);
+    bool processConditional(StoreIOBuffer &result);
     void cacheHit(StoreIOBuffer result);
     void handleIMSReply(StoreIOBuffer result);
     void sendMoreData(StoreIOBuffer result);