From: Christos Tsantilas Date: Thu, 2 Apr 2020 15:21:28 +0000 (+0000) Subject: Restore PURGE miss replies to be "404 Not Found", not "0 Init" (#586) X-Git-Tag: SQUID_4_12~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a195acc06c086dadd3f3b4f4efba5c5a72315b6;p=thirdparty%2Fsquid.git Restore PURGE miss replies to be "404 Not Found", not "0 Init" (#586) 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. --- diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index e4bdbd8cbb..9d7db62cf3 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -1090,6 +1090,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. diff --git a/src/http/StatusLine.cc b/src/http/StatusLine.cc index 6e14ff1ef2..cf3c51c960 100644 --- a/src/http/StatusLine.cc +++ b/src/http/StatusLine.cc @@ -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); } /*