]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 4563: duplicate code in httpMakeVaryMark
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 15 Aug 2016 11:26:37 +0000 (23:26 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 15 Aug 2016 11:26:37 +0000 (23:26 +1200)
src/http.cc

index f35eb52b7c0f0e7ff3404b2d18ba5907dee6eee6..a0a30cb80b9fd034e43f5752ddf8572b08598bee 100644 (file)
@@ -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);