bneradt commented on code in PR #12494:
URL: https://github.com/apache/trafficserver/pull/12494#discussion_r2354124887


##########
plugins/esi/http_utils.cc:
##########
@@ -0,0 +1,67 @@
+/** @file
+
+  Implementation of HTTP utilities for ESI plugins.
+
+  @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 "http_utils.h"
+
+#include <ts/ts.h>
+
+std::string
+getRequestUrlString(TSHttpTxn txnp)
+{
+  std::string request_url = UNKNOWN_URL_STRING;
+  TSMBuffer   req_bufp;
+  TSMLoc      req_hdr_loc;
+  TSMLoc      url_loc;
+
+  if (TSHttpTxnClientReqGet(txnp, &req_bufp, &req_hdr_loc) == TS_SUCCESS) {
+    if (TSHttpTxnPristineUrlGet(txnp, &req_bufp, &url_loc) == TS_SUCCESS) {
+      int   length     = 0;
+      char *url_string = TSUrlStringGet(req_bufp, url_loc, &length);
+      if (url_string) {
+        request_url.assign(url_string, length);
+        TSfree(url_string);
+      }

Review Comment:
   > Seems like this could just call the new getUrlString.
   
   Yes, good find.
   
   > Consider returning std::optional<std::string> instead of a magic value if 
that seems appropriate.
   
   Let's stick with `UNKNOWN_URL_STRING` since that gets used by the caller for 
the error message when the URL could not be received. Otherwise we'll have a 
bunch of `url_string ? url_string.value() : "(unknown)"` calls. 



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