This is an automated email from the ASF dual-hosted git repository.

cmcfarlen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 756deef4fa Warn if existing remap shadows inserted remap (#12526)
756deef4fa is described below

commit 756deef4fa4a43543b989b8fd31faca6217896ed
Author: Chris McFarlen <[email protected]>
AuthorDate: Mon Oct 6 12:35:56 2025 -0400

    Warn if existing remap shadows inserted remap (#12526)
    
    * Warn if existing remap shadows inserted remap
    
    * Includee bwformat for URL
---
 include/proxy/hdrs/URL.h                    |  5 +++++
 src/proxy/hdrs/URL.cc                       | 16 ++++++++++++++++
 src/proxy/http/remap/UrlMappingPathIndex.cc | 10 +++++++++-
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/include/proxy/hdrs/URL.h b/include/proxy/hdrs/URL.h
index 3c3620c361..e8aeee0978 100644
--- a/include/proxy/hdrs/URL.h
+++ b/include/proxy/hdrs/URL.h
@@ -786,3 +786,8 @@ URL::unescapify(Arena *arena, const char *str, int length)
 {
   return url_unescapify(arena, str, length);
 }
+
+namespace swoc
+{
+BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &, URL const &url);
+} // namespace swoc
diff --git a/src/proxy/hdrs/URL.cc b/src/proxy/hdrs/URL.cc
index 1c0b0c1ab8..fa75ae25df 100644
--- a/src/proxy/hdrs/URL.cc
+++ b/src/proxy/hdrs/URL.cc
@@ -1996,3 +1996,19 @@ url_host_CryptoHash_get(URLImpl *url, CryptoHash *hash)
   ctx.update(&port, sizeof(port));
   ctx.finalize(*hash);
 }
+
+namespace swoc
+{
+BufferWriter &
+bwformat(BufferWriter &w, bwf::Spec const &, URL const &url)
+{
+  char buff[2048];
+  int  idx    = 0;
+  int  offset = 0;
+  url.print(buff, sizeof(buff), &idx, &offset);
+
+  w.write(buff, idx);
+
+  return w;
+}
+} // namespace swoc
diff --git a/src/proxy/http/remap/UrlMappingPathIndex.cc 
b/src/proxy/http/remap/UrlMappingPathIndex.cc
index aaa1c798bf..5fe09b24c3 100644
--- a/src/proxy/http/remap/UrlMappingPathIndex.cc
+++ b/src/proxy/http/remap/UrlMappingPathIndex.cc
@@ -21,6 +21,7 @@
     limitations under the License.
 */
 
+#include <tsutil/ts_bw_format.h>
 #include "proxy/http/remap/UrlMappingPathIndex.h"
 
 namespace
@@ -46,14 +47,21 @@ UrlMappingPathIndex::Insert(url_mapping *mapping)
   UrlMappingTrie *trie;
 
   trie = _GetTrie(&(mapping->fromURL), scheme_idx, port);
+  auto from_path{mapping->fromURL.path_get()};
 
   if (!trie) {
     trie = new UrlMappingTrie();
     m_tries.insert(UrlMappingGroup::value_type(UrlMappingTrieKey(scheme_idx, 
port), trie));
     Dbg(dbg_ctl_UrlMappingPathIndex_Insert, "Created new trie for scheme 
index, port combo <%d, %d>", scheme_idx, port);
+  } else {
+    Dbg(dbg_ctl_UrlMappingPathIndex_Insert, "-- Checking for existing entry 
%*s", static_cast<int>(from_path.length()),
+        from_path.data());
+    if (auto retval = trie->Search(from_path.data(), from_path.length()); 
retval && retval->getRank() < mapping->getRank()) {
+      swoc::bwprint(ts::bw_dbg, "Exising remap {} shadows {}", 
retval->fromURL, mapping->fromURL);
+      Warning("%s", ts::bw_dbg.c_str());
+    }
   }
 
-  auto from_path{mapping->fromURL.path_get()};
   if (!trie->Insert(from_path.data(), mapping, mapping->getRank(), 
static_cast<int>(from_path.length()))) {
     Error("Couldn't insert into trie!");
     return false;

Reply via email to