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


##########
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:
   In practice this works as only the MLocs are allocated/deallocated.  The 
std::string_view points to valid memory inside the header.  Since it's not 
explicitly documented as part of the API I guess we can make this change.



-- 
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