From: Amos Jeffries Date: Mon, 15 Aug 2016 11:26:37 +0000 (+1200) Subject: Bug 4563: duplicate code in httpMakeVaryMark X-Git-Tag: SQUID_4_0_14~30 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f5df20408d812f91abd5b8a66923dd402b2d4cbf;p=thirdparty%2Fsquid.git Bug 4563: duplicate code in httpMakeVaryMark --- diff --git a/src/http.cc b/src/http.cc index f35eb52b7c..a0a30cb80b 100644 --- a/src/http.cc +++ b/src/http.cc @@ -571,23 +571,14 @@ HttpStateData::cacheableReply() /* NOTREACHED */ } -/* - * For Vary, store the relevant request headers as - * virtual headers in the reply - * Returns an empty SBuf if the variance cannot be stored - */ -SBuf -httpMakeVaryMark(HttpRequest * request, HttpReply const * reply) +/// assemble a variant key (vary-mark) from the given Vary header and HTTP request +static void +assembleVaryKey(String &vary, SBuf &vstr, const HttpRequest &request) { - String vary, hdr; - const char *pos = NULL; - const char *item; - const char *value; - int ilen; - SBuf vstr; static const SBuf asterisk("*"); - - vary = reply->header.getList(Http::HdrType::VARY); + const char *pos = nullptr; + const char *item = nullptr; + int ilen = 0; while (strListGetItem(&vary, ',', &item, &ilen, &pos)) { SBuf name(item, ilen); @@ -599,8 +590,8 @@ httpMakeVaryMark(HttpRequest * request, HttpReply const * reply) if (!vstr.isEmpty()) vstr.append(", ", 2); vstr.append(name); - hdr = request->header.getByName(name); - value = hdr.termedBuf(); + String hdr(request.header.getByName(name)); + const char *value = hdr.termedBuf(); if (value) { value = rfc1738_escape_part(value); vstr.append("=\"", 2); @@ -610,37 +601,26 @@ httpMakeVaryMark(HttpRequest * request, HttpReply const * reply) hdr.clean(); } +} - vary.clean(); -#if X_ACCELERATOR_VARY - - pos = NULL; - vary = reply->header.getList(Http::HdrType::HDR_X_ACCELERATOR_VARY); - - while (strListGetItem(&vary, ',', &item, &ilen, &pos)) { - SBuf name(item, ilen); - if (name == asterisk) { - vstr.clear(); - break; - } - name.toLower(); - if (!vstr.isEmpty()) - vstr.append(", ", 2); - vstr.append(name); - hdr = request->header.getByName(name); - value = hdr.termedBuf(); - - if (value) { - value = rfc1738_escape_part(value); - vstr.append("=\"", 2); - vstr.append(value); - vstr.append("\"", 1); - } +/* + * For Vary, store the relevant request headers as + * virtual headers in the reply + * Returns an empty SBuf if the variance cannot be stored + */ +SBuf +httpMakeVaryMark(HttpRequest * request, HttpReply const * reply) +{ + SBuf vstr; + String vary; - hdr.clean(); - } + vary = reply->header.getList(Http::HdrType::VARY); + assembleVaryKey(vary, vstr, *request); +#if X_ACCELERATOR_VARY vary.clean(); + vary = reply->header.getList(Http::HdrType::HDR_X_ACCELERATOR_VARY); + assembleVaryKey(vary, vstr, *request); #endif debugs(11, 3, vstr);