]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Log "-" instead of the made-up method "NONE". (#486)
authorAlex Rousskov <rousskov@measurement-factory.com>
Sat, 28 Sep 2019 13:58:28 +0000 (13:58 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Mon, 30 Sep 2019 13:59:48 +0000 (13:59 +0000)
Also useful for the future ALE-using context-reporting code that must be
silent regarding unknowns, including unknown request methods.

src/AccessLogEntry.cc
src/AccessLogEntry.h
src/format/Format.cc
src/http/RequestMethod.h

index 35e998f1ff0054810e230f3ee764dafb04d038eb..c1a8b15a364308df139bc6d719596b7d50c455d4 100644 (file)
@@ -49,13 +49,16 @@ AccessLogEntry::getLogClientIp(char *buf, size_t bufsz) const
 SBuf
 AccessLogEntry::getLogMethod() const
 {
+    static const SBuf dash("-");
     SBuf method;
     if (icp.opcode)
         method.append(icp_opcode_str[icp.opcode]);
     else if (htcp.opcode)
         method.append(htcp.opcode);
-    else
+    else if (http.method)
         method = http.method.image();
+    else
+        method = dash;
     return method;
 }
 
index e048ea05fcd7ebc5d203dd4c2940a061b7aeaea1..7168562db33583ea111127c74c179063b8b0d5dc 100644 (file)
@@ -56,6 +56,9 @@ public:
     /// Fetch the external ACL provided 'user=' string, or nil if none is available.
     const char *getExtUser() const;
 
+    /// whether we know what the request method is
+    bool hasLogMethod() const { return icp.opcode || htcp.opcode || http.method; }
+
     /// Fetch the transaction method string (ICP opcode, HTCP opcode or HTTP method)
     SBuf getLogMethod() const;
 
index 3bb426895eae27a76c1a8ec0422dc76aa63359e9..7d0196d54f6b1fd95d9906af7ff0258290d15950 100644 (file)
@@ -1087,9 +1087,11 @@ Format::Format::assemble(MemBuf &mb, const AccessLogEntry::Pointer &al, int logS
             break;
 
         case LFT_REQUEST_METHOD:
-            sb = al->getLogMethod();
-            out = sb.c_str();
-            quote = 1;
+            if (al->hasLogMethod()) {
+                sb = al->getLogMethod();
+                out = sb.c_str();
+                quote = 1;
+            }
             break;
 
         case LFT_REQUEST_URI:
index 98d447cb0f8e9ce3bd97b103189ee84d187924ae..9b6b9404ec682653c0fb23ca2dc2ab58f001cb1c 100644 (file)
@@ -44,6 +44,9 @@ public:
         return *this;
     }
 
+    /// whether the method is set/known
+    explicit operator bool() const { return theMethod != Http::METHOD_NONE; }
+
     bool operator == (Http::MethodType const & aMethod) const { return theMethod == aMethod; }
     bool operator == (HttpRequestMethod const & aMethod) const {
         return theMethod == aMethod.theMethod &&