From 0c90d3b190237bac3017096a9e2bbe278c665ac6 Mon Sep 17 00:00:00 2001 From: Dave Dykstra Date: Mon, 21 Mar 2016 05:20:28 +1300 Subject: [PATCH] Bug 2831: Cache-control: max-age not sent on TCP_IMS_HIT/304 --- src/HttpMsg.cc | 20 ++++++++++++++++++++ src/HttpMsg.h | 3 +++ src/HttpReply.cc | 3 ++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/HttpMsg.cc b/src/HttpMsg.cc index fea8bb9ebd..5e42e4f09d 100644 --- a/src/HttpMsg.cc +++ b/src/HttpMsg.cc @@ -11,6 +11,7 @@ #include "squid.h" #include "Debug.h" #include "http/one/Parser.h" +#include "HttpHdrCc.h" #include "HttpHeaderTools.h" #include "HttpMsg.h" #include "MemBuf.h" @@ -33,6 +34,25 @@ HttpMsg::~HttpMsg() assert(!body_pipe); } +void +HttpMsg::putCc(const HttpHdrCc *otherCc) +{ + // get rid of the old CC, if any + if (cache_control) { + delete cache_control; + cache_control = nullptr; + if (!otherCc) + header.delById(HDR_CACHE_CONTROL); + // else it will be deleted inside putCc() below + } + + // add new CC, if any + if (otherCc) { + cache_control = new HttpHdrCc(*otherCc); + header.putCc(cache_control); + } +} + HttpMsgParseState &operator++ (HttpMsgParseState &aState) { int tmp = (int)aState; diff --git a/src/HttpMsg.h b/src/HttpMsg.h index f783886d04..0d16a5d681 100644 --- a/src/HttpMsg.h +++ b/src/HttpMsg.h @@ -87,6 +87,9 @@ public: uint32_t sources; ///< The message sources + /// copies Cache-Control header to this message + void putCc(const HttpHdrCc *otherCc); + // returns true and sets hdr_sz on success // returns false and sets *error to zero when needs more data // returns false and sets *error to a positive Http::StatusCode on error diff --git a/src/HttpReply.cc b/src/HttpReply.cc index eed1d1de79..eb36a2929a 100644 --- a/src/HttpReply.cc +++ b/src/HttpReply.cc @@ -146,7 +146,6 @@ HttpReply::make304() const rv->last_modified = last_modified; rv->expires = expires; rv->content_type = content_type; - /* rv->cache_control */ /* rv->content_range */ /* rv->keep_alive */ rv->sline.set(Http::ProtocolVersion(), Http::scNotModified, NULL); @@ -156,6 +155,8 @@ HttpReply::make304() const rv->header.addEntry(e->clone()); } + rv->putCc(cache_control); + /* rv->body */ return rv; } -- 2.47.2