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 f4cd38bf33 hrw: forward declare template specializations (#12456)
f4cd38bf33 is described below

commit f4cd38bf335786b5572558029d998da4dc498d96
Author: Chris McFarlen <[email protected]>
AuthorDate: Tue Aug 19 11:52:48 2025 -0500

    hrw: forward declare template specializations (#12456)
    
    * Add unit test for hrw
    
    * Add forward declarations to matcher.h
    
    * cleanup dbg
    
    * Fix link issues
---
 plugins/header_rewrite/CMakeLists.txt    |   6 ++
 plugins/header_rewrite/header_rewrite.cc |   6 --
 plugins/header_rewrite/matcher.cc        |  10 +++
 plugins/header_rewrite/matcher.h         |   8 +++
 plugins/header_rewrite/matcher_tests.cc  | 109 +++++++++++++++++++++++++++++++
 5 files changed, 133 insertions(+), 6 deletions(-)

diff --git a/plugins/header_rewrite/CMakeLists.txt 
b/plugins/header_rewrite/CMakeLists.txt
index e1a8ef7bc6..028b80bb40 100644
--- a/plugins/header_rewrite/CMakeLists.txt
+++ b/plugins/header_rewrite/CMakeLists.txt
@@ -57,6 +57,12 @@ if(BUILD_TESTING)
   if(maxminddb_FOUND)
     target_link_libraries(test_header_rewrite PRIVATE maxminddb::maxminddb)
   endif()
+
+  add_executable(test_matcher matcher_tests.cc matcher.cc lulu.cc 
regex_helper.cc resources.cc)
+  add_test(NAME test_matcher COMMAND $<TARGET_FILE:test_matcher>)
+
+  target_link_libraries(test_matcher PRIVATE catch2::catch2 ts::tscore 
libswoc::libswoc PCRE::PCRE)
+
 endif()
 verify_global_plugin(header_rewrite)
 verify_remap_plugin(header_rewrite)
diff --git a/plugins/header_rewrite/header_rewrite.cc 
b/plugins/header_rewrite/header_rewrite.cc
index 86f7bdf529..9f5bdce815 100644
--- a/plugins/header_rewrite/header_rewrite.cc
+++ b/plugins/header_rewrite/header_rewrite.cc
@@ -40,12 +40,6 @@
 // Debugs
 namespace header_rewrite_ns
 {
-const char PLUGIN_NAME[]     = "header_rewrite";
-const char PLUGIN_NAME_DBG[] = "dbg_header_rewrite";
-
-DbgCtl dbg_ctl{PLUGIN_NAME_DBG};
-DbgCtl pi_dbg_ctl{PLUGIN_NAME};
-
 std::once_flag initHRWLibs;
 PluginFactory  plugin_factory;
 
diff --git a/plugins/header_rewrite/matcher.cc 
b/plugins/header_rewrite/matcher.cc
index 75faa6a2a1..f4aec365e1 100644
--- a/plugins/header_rewrite/matcher.cc
+++ b/plugins/header_rewrite/matcher.cc
@@ -21,11 +21,21 @@
   limitations under the License.
 */
 
+#include "tsutil/DbgCtl.h"
 #include <string>
 #include <algorithm>
 
 #include "matcher.h"
 
+namespace header_rewrite_ns
+{
+const char PLUGIN_NAME[]     = "header_rewrite";
+const char PLUGIN_NAME_DBG[] = "dbg_header_rewrite";
+
+DbgCtl dbg_ctl{PLUGIN_NAME_DBG};
+DbgCtl pi_dbg_ctl{PLUGIN_NAME};
+} // namespace header_rewrite_ns
+
 static bool
 match_with_modifiers(std::string_view rhs, std::string_view lhs, CondModifiers 
mods)
 {
diff --git a/plugins/header_rewrite/matcher.h b/plugins/header_rewrite/matcher.h
index 3099b300f8..1a61b3e505 100644
--- a/plugins/header_rewrite/matcher.h
+++ b/plugins/header_rewrite/matcher.h
@@ -380,3 +380,11 @@ private:
   std::variant<T, std::set<T>, swoc::IPRangeSet, regexHelper> _data;
   CondModifiers                                               _mods = 
CondModifiers::NONE;
 };
+
+// forward declare spcializations implemented in matcher.cc
+
+template <> bool Matchers<std::string>::test_eq(const std::string &) const;
+
+template <> bool Matchers<std::string>::test_set(const std::string &) const;
+
+template <> bool Matchers<const sockaddr *>::test(const sockaddr *const &, 
const Resources &) const;
diff --git a/plugins/header_rewrite/matcher_tests.cc 
b/plugins/header_rewrite/matcher_tests.cc
new file mode 100644
index 0000000000..eb730bc4fd
--- /dev/null
+++ b/plugins/header_rewrite/matcher_tests.cc
@@ -0,0 +1,109 @@
+/**
+  @file Test for matcher.cc
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+*/
+
+#include "matcher.h"
+#include "ts/apidefs.h"
+#define CATCH_CONFIG_MAIN
+#include "catch.hpp"
+
+int
+_TSAssert(const char *, const char *, int)
+{
+  return 0;
+}
+
+void
+TSError(const char *fmt, ...)
+{
+  va_list args;
+
+  va_start(args, fmt);
+  vfprintf(stderr, fmt, args);
+  va_end(args);
+  fprintf(stderr, "\n");
+}
+
+TSHttpStatus
+TSHttpHdrStatusGet(TSMBuffer, TSMLoc)
+{
+  return TS_HTTP_STATUS_OK;
+}
+
+TSReturnCode
+TSHandleMLocRelease(TSMBuffer, TSMLoc, TSMLoc)
+{
+  return TS_SUCCESS;
+}
+
+const char *
+TSHttpHookNameLookup(TSHttpHookID)
+{
+  return nullptr;
+}
+
+TSReturnCode
+TSHttpTxnClientReqGet(TSHttpTxn, TSMBuffer *, TSMLoc *)
+{
+  return TS_SUCCESS;
+}
+
+TSReturnCode
+TSHttpTxnServerReqGet(TSHttpTxn, TSMBuffer *, TSMLoc *)
+{
+  return TS_SUCCESS;
+}
+
+TSReturnCode
+TSHttpTxnClientRespGet(TSHttpTxn, TSMBuffer *, TSMLoc *)
+{
+  return TS_SUCCESS;
+}
+
+TSReturnCode
+TSHttpTxnServerRespGet(TSHttpTxn, TSMBuffer *, TSMLoc *)
+{
+  return TS_SUCCESS;
+}
+
+ClassAllocator<ProxyMutex> mutexAllocator("mutexAllocator");
+
+TEST_CASE("Matcher", "[plugins][header_rewrite]")
+{
+  Matchers<std::string> foo(MATCH_EQUAL);
+  TSHttpTxn             txn = nullptr;
+  TSCont                c   = nullptr;
+  Resources             res(txn, c);
+
+  foo.set("FOO", CondModifiers::MOD_NOCASE);
+  REQUIRE(foo.test("foo", res) == true);
+}
+
+TEST_CASE("MatcherSet", "[plugins][header_rewrite]")
+{
+  Matchers<std::string> foo(MATCH_SET);
+  TSHttpTxn             txn = nullptr;
+  TSCont                c   = nullptr;
+  Resources             res(txn, c);
+
+  foo.set("foo, bar, baz", CondModifiers::MOD_NOCASE);
+  REQUIRE(foo.test("FOO", res) == true);
+}

Reply via email to