From: Garri Djavadyan Date: Sat, 17 Dec 2016 13:56:49 +0000 (+1300) Subject: Bug 4169: HIT marked as MISS when If-None-Match does not match X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fv3.1;p=thirdparty%2Fsquid.git Bug 4169: HIT marked as MISS when If-None-Match does not match --- diff --git a/src/access_log.cc b/src/access_log.cc index 3c0e3dbe82..6a21bb4bfd 100644 --- a/src/access_log.cc +++ b/src/access_log.cc @@ -2451,6 +2451,9 @@ logTypeIsATcpHit(log_type code) if (code == LOG_TCP_HIT) return 1; + if (code == LOG_TCP_INM_HIT) + return 1; + if (code == LOG_TCP_IMS_HIT) return 1; diff --git a/src/client_side.cc b/src/client_side.cc index e5fe4106fd..47787d0911 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -365,6 +365,7 @@ clientUpdateStatHistCounters(log_type logType, int svc_time) statHistCount(&statCounter.client_http.nh_svc_time, svc_time); break; + case LOG_TCP_INM_HIT: case LOG_TCP_IMS_HIT: statHistCount(&statCounter.client_http.nm_svc_time, svc_time); break; diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index 9686a9b66c..8b4774fea4 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -706,40 +706,27 @@ clientReplyContext::processConditional(StoreIOBuffer &result) return true; } - bool matchedIfNoneMatch = false; if (r.header.has(HDR_IF_NONE_MATCH)) { - if (!e->hasIfNoneMatchEtag(r)) { - // RFC 2616: ignore IMS if If-None-Match did not match - r.flags.ims = 0; - r.ims = -1; - r.imslen = 0; - r.header.delById(HDR_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(HDR_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)) { - 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 @@ -1835,7 +1822,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, request_flags()); e = http->storeEntry(); diff --git a/src/enums.h b/src/enums.h index f974ef863c..5dd2e5c626 100644 --- a/src/enums.h +++ b/src/enums.h @@ -45,6 +45,7 @@ typedef enum { LOG_TCP_REFRESH_FAIL_ERR, // refresh from origin failed, error forwarded LOG_TCP_REFRESH_MODIFIED, // refresh from origin replaced existing entry LOG_TCP_CLIENT_REFRESH_MISS, + LOG_TCP_INM_HIT, LOG_TCP_IMS_HIT, LOG_TCP_SWAPFAIL_MISS, LOG_TCP_NEGATIVE_HIT,