From: Garri Djavadyan Date: Fri, 11 Nov 2016 06:03:25 +0000 (+1300) Subject: Bug 3379: Combination of If-Match and a Cache Hit result in TCP Connection Failure X-Git-Tag: SQUID_3_5_23~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eea66ca6607ae2a034a56b90595a2cd6ce65c2a0;p=thirdparty%2Fsquid.git Bug 3379: Combination of If-Match and a Cache Hit result in TCP Connection Failure --- diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index a7046b86ce..257638079a 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -589,6 +589,7 @@ clientReplyContext::cacheHit(StoreIOBuffer result) debugs(88, 5, "negative-HIT"); http->logType = LOG_TCP_NEGATIVE_HIT; sendMoreData(result); + return; } else if (blockedHit()) { debugs(88, 5, "send_hit forces a MISS"); http->logType = LOG_TCP_MISS; @@ -641,27 +642,29 @@ clientReplyContext::cacheHit(StoreIOBuffer result) http->logType = LOG_TCP_MISS; processMiss(); } + return; } else if (r->conditional()) { debugs(88, 5, "conditional HIT"); - processConditional(result); - } else { - /* - * plain ol' cache hit - */ - debugs(88, 5, "plain old 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); } /** @@ -755,17 +758,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; @@ -773,7 +775,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; @@ -786,14 +788,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 @@ -805,19 +807,20 @@ clientReplyContext::processConditional(StoreIOBuffer &result) if (e->modifiedSince(r.ims, r.imslen)) { 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; } /// whether squid.conf send_hit prevents us from serving this hit diff --git a/src/client_side_reply.h b/src/client_side_reply.h index 8a46ba37e0..4e01e25223 100644 --- a/src/client_side_reply.h +++ b/src/client_side_reply.h @@ -114,7 +114,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);