]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Restore PURGE miss replies to be "404 Not Found", not "0 Init" (#586)
authorChristos Tsantilas <christos@chtsanti.net>
Thu, 2 Apr 2020 15:21:28 +0000 (15:21 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Thu, 2 Apr 2020 15:21:34 +0000 (15:21 +0000)
Since commit 6956579, PURGE requests resulted in invalid HTTP responses
with zero status code when Store lacked both GET and HEAD entries with
the requested URI.

Also adjusted Http::StatusLine packing code to avoid generating similar
invalid responses in the future (and to attract developer attention to
their presence in the code logic with a BUG message).

This is a Measurement Factory project.

src/client_side_reply.cc
src/http/StatusLine.cc

index e1e8fce2fbd03131de35fcb8f330ce664d409fde..d5fec1f826458b17eed927dbc8a4395631b8dd41 100644 (file)
@@ -1048,8 +1048,6 @@ void
 clientReplyContext::purgeDoPurgeGet(StoreEntry *newEntry)
 {
     if (newEntry) {
-        /* Move to new() when that is created */
-        purgeStatus = Http::scNotFound;
         /* Release the cached URI */
         debugs(88, 4, "clientPurgeRequest: GET '" << newEntry->url() << "'" );
 #if USE_HTCP
@@ -1103,6 +1101,9 @@ clientReplyContext::purgeDoPurgeHead(StoreEntry *newEntry)
         }
     }
 
+    if (purgeStatus == Http::scNone)
+        purgeStatus = Http::scNotFound;
+
     /*
      * Make a new entry to hold the reply to be written
      * to the client.
index bc1514f76ac8ba3fe29e04790709c633e7ed2235..530a2afffc61f2d857df5baf0589d3a47644b876 100644 (file)
@@ -47,6 +47,17 @@ Http::StatusLine::packInto(Packable * p) const
 {
     assert(p);
 
+    auto packedStatus = status();
+    auto packedReason = reason();
+
+    if (packedStatus == Http::scNone) {
+        static unsigned int reports = 0;
+        if (++reports <= 100)
+            debugs(57, DBG_IMPORTANT, "BUG: Generated response lacks status code");
+        packedStatus = Http::scInternalServerError;
+        packedReason = Http::StatusCodeString(packedStatus); // ignore custom reason_ (if any)
+    }
+
     /* local constants */
     /* AYJ: see bug 2469 - RFC2616 confirms stating 'SP characters' plural! */
     static const char *Http1StatusLineFormat = "HTTP/%d.%d %3d %s\r\n";
@@ -56,15 +67,15 @@ Http::StatusLine::packInto(Packable * p) const
     if (protocol == AnyP::PROTO_ICY) {
         debugs(57, 9, "packing sline " << this << " using " << p << ":");
         debugs(57, 9, "FORMAT=" << IcyStatusLineFormat );
-        debugs(57, 9, "ICY " << status() << " " << reason());
-        p->appendf(IcyStatusLineFormat, status(), reason());
+        debugs(57, 9, "ICY " << packedStatus << " " << packedReason);
+        p->appendf(IcyStatusLineFormat, packedStatus, packedReason);
         return;
     }
 
     debugs(57, 9, "packing sline " << this << " using " << p << ":");
     debugs(57, 9, "FORMAT=" << Http1StatusLineFormat );
-    debugs(57, 9, "HTTP/" << version.major << "." << version.minor << " " << status() << " " << reason());
-    p->appendf(Http1StatusLineFormat, version.major, version.minor, status(), reason());
+    debugs(57, 9, "HTTP/" << version.major << "." << version.minor << " " << packedStatus << " " << packedReason);
+    p->appendf(Http1StatusLineFormat, version.major, version.minor, packedStatus, packedReason);
 }
 
 /*