------------------------------------------------------------ revno: 14933 revision-id: squid3@treenet.co.nz-20161111020824-u9btqhagaga28su7 parent: squidadm@squid-cache.org-20161109133341-x7jbfctqkx0qqnaz fixes bug: http://bugs.squid-cache.org/show_bug.cgi?id=3379 author: Garri Djavadyan , Amos Jeffries committer: Amos Jeffries branch nick: 4 timestamp: Fri 2016-11-11 15:08:24 +1300 message: Bug 3379: Combination of If-Match and a Cache Hit result in TCP Connection Failure ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20161111020824-u9btqhagaga28su7 # target_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # testament_sha1: a527625bc76dc309ed676bfd039815947308851f # timestamp: 2016-11-11 02:51:12 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/trunk # base_revision_id: squidadm@squid-cache.org-20161109133341-\ # x7jbfctqkx0qqnaz # # Begin patch === modified file 'src/client_side_reply.cc' --- src/client_side_reply.cc 2016-10-08 22:19:44 +0000 +++ src/client_side_reply.cc 2016-11-11 02:08:24 +0000 @@ -661,25 +661,26 @@ } } 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); } /** @@ -773,17 +774,16 @@ } /// 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; @@ -791,7 +791,7 @@ if (r.header.has(Http::HdrType::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; @@ -804,14 +804,14 @@ r.header.delById(Http::HdrType::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 @@ -823,19 +823,20 @@ 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; + + } else { + // otherwise reply with 304 Not Modified + sendNotModified(); } - - // otherwise reply with 304 Not Modified - sendNotModified(); + return true; } + + return false; } /// whether squid.conf send_hit prevents us from serving this hit === modified file 'src/client_side_reply.h' --- src/client_side_reply.h 2016-07-23 13:36:56 +0000 +++ src/client_side_reply.h 2016-11-11 02:08:24 +0000 @@ -115,7 +115,7 @@ 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); ------------------------------------------------------------ revno: 14953 revision-id: squid3@treenet.co.nz-20161211094622-0891phdz2wnrryw2 parent: squid3@treenet.co.nz-20161210223657-84h35jlf2mbv9jtj fixes bug: http://bugs.squid-cache.org/show_bug.cgi?id=4169 author: Garri Djavadyan committer: Amos Jeffries branch nick: trunk timestamp: Sun 2016-12-11 22:46:22 +1300 message: Bug 4169: HIT marked as MISS when If-None-Match does not match ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20161211094622-0891phdz2wnrryw2 # target_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # testament_sha1: 2d7cae5ffb9868605b18416f0ae61dfd763a92da # timestamp: 2016-12-11 09:51:11 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/4 # base_revision_id: squid3@treenet.co.nz-20161210223657-\ # 84h35jlf2mbv9jtj # # Begin patch === modified file 'src/LogTags.cc' --- src/LogTags.cc 2016-10-08 22:19:44 +0000 +++ src/LogTags.cc 2016-12-11 09:46:22 +0000 @@ -21,6 +21,7 @@ "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 @@ 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) || === modified file 'src/LogTags.h' --- src/LogTags.h 2016-10-08 22:19:44 +0000 +++ src/LogTags.h 2016-12-11 09:46:22 +0000 @@ -28,6 +28,7 @@ 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, === modified file 'src/client_side.cc' --- src/client_side.cc 2016-11-28 10:08:16 +0000 +++ src/client_side.cc 2016-12-11 09:46:22 +0000 @@ -229,6 +229,7 @@ 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; === modified file 'src/client_side_reply.cc' --- src/client_side_reply.cc 2016-12-09 04:42:34 +0000 +++ src/client_side_reply.cc 2016-12-11 09:46:22 +0000 @@ -796,40 +796,27 @@ 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 @@ 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();