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


##########
tests/gold_tests/pluginTest/lua/lua_proxy_protocol.test.py:
##########
@@ -0,0 +1,103 @@
+'''
+Test Lua plugin PROXY protocol support
+'''
+#  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.
+
+import os

Review Comment:
   Import of 'os' is not used.
   ```suggestion
   
   ```



##########
plugins/lua/ts_lua_client_request.cc:
##########
@@ -1139,3 +1162,92 @@ ts_lua_client_request_get_ssl_curve(lua_State *L)
 
   return 1;
 }
+
+static void
+ts_lua_inject_client_request_pp_info_api(lua_State *L)
+{
+  size_t i;
+
+  for (i = 0; i < sizeof(ts_lua_pp_info_key_vars) / sizeof(ts_lua_var_item); 
i++) {
+    lua_pushinteger(L, ts_lua_pp_info_key_vars[i].nvar);
+    lua_setglobal(L, ts_lua_pp_info_key_vars[i].svar);
+  }
+
+  lua_pushcfunction(L, ts_lua_client_request_get_pp_info);
+  lua_setfield(L, -2, "get_pp_info");
+
+  lua_pushcfunction(L, ts_lua_client_request_get_pp_info_int);
+  lua_setfield(L, -2, "get_pp_info_int");
+}
+
+static int
+ts_lua_client_request_get_pp_info(lua_State *L)
+{
+  uint16_t         key;
+  const char      *value = nullptr;
+  int              length;
+  ts_lua_http_ctx *http_ctx;
+  TSHttpSsn        ssnp;
+  TSVConn          client_conn;
+
+  GET_HTTP_CONTEXT(http_ctx, L);
+
+  key = static_cast<uint16_t>(luaL_checkinteger(L, 1));
+
+  ssnp        = TSHttpTxnSsnGet(http_ctx->txnp);
+  client_conn = TSHttpSsnClientVConnGet(ssnp);
+
+  if (TSVConnPPInfoGet(client_conn, key, &value, &length) == TS_SUCCESS) {
+    if (key == TS_PP_INFO_SRC_ADDR || key == TS_PP_INFO_DST_ADDR) {
+      // For addresses, convert sockaddr to string
+      char             ip_str[INET6_ADDRSTRLEN];
+      const sockaddr  *addr = reinterpret_cast<const sockaddr *>(value);
+      const sockaddr_in *addr_in;
+      const sockaddr_in6 *addr_in6;
+
+      if (addr->sa_family == AF_INET) {
+        addr_in = reinterpret_cast<const sockaddr_in *>(addr);
+        inet_ntop(AF_INET, &addr_in->sin_addr, ip_str, sizeof(ip_str));
+      } else if (addr->sa_family == AF_INET6) {
+        addr_in6 = reinterpret_cast<const sockaddr_in6 *>(addr);

Review Comment:
   [nitpick] The variables `addr_in` and `addr_in6` are declared but not 
initialized. While they are assigned before use, modern C++ best practices 
recommend declaring variables at the point of initialization or as close to 
their use as possible. Consider moving the declarations to lines 1209 and 1212 
respectively, combining declaration with initialization:
   ```cpp
   const sockaddr_in *addr_in = reinterpret_cast<const sockaddr_in *>(addr);
   ```
   and
   ```cpp
   const sockaddr_in6 *addr_in6 = reinterpret_cast<const sockaddr_in6 *>(addr);
   ```
   ```suggestion
   
         if (addr->sa_family == AF_INET) {
           const sockaddr_in *addr_in = reinterpret_cast<const sockaddr_in 
*>(addr);
           inet_ntop(AF_INET, &addr_in->sin_addr, ip_str, sizeof(ip_str));
         } else if (addr->sa_family == AF_INET6) {
           const sockaddr_in6 *addr_in6 = reinterpret_cast<const sockaddr_in6 
*>(addr);
   ```



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