Copilot commented on code in PR #13801:
URL: https://github.com/apache/trafficserver/pull/13801#discussion_r4232477447


##########
tests/gold_tests/parent_proxy/plugins/parent_override_test.cc:
##########
@@ -0,0 +1,110 @@
+/** @file
+
+  A test plugin that routes a transaction to a plugin-chosen parent.
+
+  The X-Parent-Override request header selects the API:
+    proxy-set       - TSHttpTxnParentProxySet()
+    response-action - TSHttpTxnResponseActionSet()
+
+  Either way the parent is 127.0.0.1:1, where nothing listens, so a request
+  routed to it fails with a 502.
+
+  @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 <ts/ts.h>
+
+#include <string_view>
+
+namespace
+{
+constexpr char             PLUGIN_NAME[]   = "parent_override_test";
+constexpr char             DEAD_PARENT[]   = "127.0.0.1";
+constexpr int              DEAD_PORT       = 1;
+constexpr std::string_view OVERRIDE_HEADER = "X-Parent-Override";
+
+DbgCtl dbg_ctl{PLUGIN_NAME};
+
+std::string_view
+override_mode(TSHttpTxn txnp)
+{
+  TSMBuffer        bufp    = nullptr;
+  TSMLoc           hdr_loc = TS_NULL_MLOC;
+  std::string_view mode;
+
+  if (TSHttpTxnClientReqGet(txnp, &bufp, &hdr_loc) != TS_SUCCESS) {
+    return mode;
+  }
+
+  TSMLoc field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, OVERRIDE_HEADER.data(), 
static_cast<int>(OVERRIDE_HEADER.size()));
+  if (field_loc != TS_NULL_MLOC) {
+    int         len   = 0;
+    char const *value = TSMimeHdrFieldValueStringGet(bufp, hdr_loc, field_loc, 
-1, &len);
+
+    if (value != nullptr) {
+      mode = {value, static_cast<size_t>(len)};
+    }
+    TSHandleMLocRelease(bufp, hdr_loc, field_loc);
+  }
+  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
+  return mode;

Review Comment:
   override_mode() returns a std::string_view that aliases header-buffer 
memory, but it releases the header MLocs before returning. This makes the 
lifetime of the referenced memory unclear/fragile and risks use-after-free if 
the SDK invalidates pointers after handle release. Prefer returning a 
std::string (copy) or performing the mode comparison while the MLocs are still 
held (e.g., parse into an enum/bool before releasing).



##########
include/ts/apidefs.h.in:
##########
@@ -922,6 +922,7 @@ enum TSOverridableConfigKey {
   TS_CONFIG_HTTP_CACHE_MAX_STALE_AGE_PERCENT,
   TS_CONFIG_HTTP_PER_SERVER_CONNECTION_METRIC_ENABLED,
   TS_CONFIG_HTTP_PER_SERVER_CONNECTION_METRIC_AGGREGATE,
+  TS_CONFIG_HTTP_BYPASS_PARENT,
   TS_CONFIG_LAST_ENTRY,

Review Comment:
   This PR introduces a new public overridable-config key 
(TS_CONFIG_HTTP_BYPASS_PARENT). The added gold tests validate conf_remap-driven 
overrides, but they don’t exercise the C API path 
(TSHttpTxnConfigIntSet/TSHttpTxnConfigIntGet) using the new enum value. Adding 
a small autest plugin-driven case that sets TS_CONFIG_HTTP_BYPASS_PARENT via 
TSHttpTxnConfigIntSet would help ensure the enum-to-record mapping is wired 
correctly and prevent regressions in the public API.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to