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


##########
tests/gold_tests/autest-site/ats_replay.test.ext:
##########
@@ -159,13 +159,18 @@ def configure_ats(obj: 'TestRun', server: 'Process', 
ats_config: dict, dns: Opti
 
     # Configure logging.yaml if specified.
     logging_yaml = ats_config.get('logging_yaml')
-    if logging_yaml != None:
-        ts.Disk.logging_yaml.AddLines(yaml.dump(logging_yaml).split('\n'))
+    if logging_yaml is not None:
+        ts.Disk.logging_yaml.AddLines(yaml.safe_dump(logging_yaml).split('\n'))
+
+    # Configure ip_allow.yaml if specified.
+    ip_allow_yaml = ats_config.get('ip_allow_yaml')
+    if ip_allow_yaml is not None:
+        
ts.Disk.ip_allow_yaml.AddLines(yaml.safe_dump(ip_allow_yaml).split('\n'))
 
     # Configure storage.yaml if specified.
     storage_yaml = ats_config.get('storage_yaml')
     if storage_yaml is not None:
-        ts.Disk.storage_yaml.AddLines(yaml.dump(storage_yaml).split('\n'))
+        ts.Disk.storage_yaml.AddLines(yaml.safe_dump(storage_yaml).split('\n'))

Review Comment:
   Using `.split('\\n')` on the YAML string will include a trailing empty 
element when the dump ends with a newline (common), and it also won’t handle 
other newline conventions. Prefer `splitlines()` (or `splitlines(False)`) here 
to avoid adding an extra blank line and to be newline-agnostic.



##########
tests/gold_tests/autest-site/ats_replay.test.ext:
##########
@@ -159,13 +159,18 @@ def configure_ats(obj: 'TestRun', server: 'Process', 
ats_config: dict, dns: Opti
 
     # Configure logging.yaml if specified.
     logging_yaml = ats_config.get('logging_yaml')
-    if logging_yaml != None:
-        ts.Disk.logging_yaml.AddLines(yaml.dump(logging_yaml).split('\n'))
+    if logging_yaml is not None:
+        ts.Disk.logging_yaml.AddLines(yaml.safe_dump(logging_yaml).split('\n'))

Review Comment:
   Using `.split('\\n')` on the YAML string will include a trailing empty 
element when the dump ends with a newline (common), and it also won’t handle 
other newline conventions. Prefer `splitlines()` (or `splitlines(False)`) here 
to avoid adding an extra blank line and to be newline-agnostic.



##########
tests/gold_tests/autest-site/ats_replay.test.ext:
##########
@@ -131,8 +131,8 @@ def configure_ats(obj: 'TestRun', server: 'Process', 
ats_config: dict, dns: Opti
 
         # Configure sni.yaml if specified.
         sni_yaml = ats_config.get('sni_yaml')
-        if sni_yaml != None:
-            ts.Disk.sni_yaml.AddLines(yaml.dump(sni_yaml).split('\n'))
+        if sni_yaml is not None:
+            ts.Disk.sni_yaml.AddLines(yaml.safe_dump(sni_yaml).split('\n'))

Review Comment:
   Using `.split('\\n')` on the YAML string will include a trailing empty 
element when the dump ends with a newline (common), and it also won’t handle 
other newline conventions. Prefer `splitlines()` (or `splitlines(False)`) here 
to avoid adding an extra blank line and to be newline-agnostic.



##########
tests/gold_tests/query/query_retry_origin.py:
##########
@@ -0,0 +1,82 @@
+'''
+An origin that closes the first connection after reading the request, without
+responding, and answers every later request with a 200.
+'''
+#  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 argparse
+import socket
+import sys
+
+
+def read_request(conn: socket.socket) -> tuple[str, bytes]:
+    data = bytearray()
+    while b'\r\n\r\n' not in data:
+        chunk = conn.recv(4096)
+        if not chunk:
+            return '', b''
+        data += chunk
+    head, _, body = data.partition(b'\r\n\r\n')
+    lines = head.decode('latin-1').split('\r\n')
+    method = lines[0].split(' ')[0]
+    length = 0
+    for line in lines[1:]:
+        name, _, value = line.partition(':')
+        if name.strip().lower() == 'content-length':
+            length = int(value.strip())
+    while len(body) < length:
+        chunk = conn.recv(4096)
+        if not chunk:
+            break
+        body += chunk
+    return method, bytes(body[:length])

Review Comment:
   This loop repeatedly concatenates `bytes` (`body += chunk`), which copies 
the buffer each iteration and can become quadratic as request bodies grow. Use 
a `bytearray` accumulator (or append to the existing `data` bytearray and 
slice) and convert to `bytes` once at the end.



##########
tests/gold_tests/autest-site/ats_replay.test.ext:
##########
@@ -159,13 +159,18 @@ def configure_ats(obj: 'TestRun', server: 'Process', 
ats_config: dict, dns: Opti
 
     # Configure logging.yaml if specified.
     logging_yaml = ats_config.get('logging_yaml')
-    if logging_yaml != None:
-        ts.Disk.logging_yaml.AddLines(yaml.dump(logging_yaml).split('\n'))
+    if logging_yaml is not None:
+        ts.Disk.logging_yaml.AddLines(yaml.safe_dump(logging_yaml).split('\n'))
+
+    # Configure ip_allow.yaml if specified.
+    ip_allow_yaml = ats_config.get('ip_allow_yaml')
+    if ip_allow_yaml is not None:
+        
ts.Disk.ip_allow_yaml.AddLines(yaml.safe_dump(ip_allow_yaml).split('\n'))

Review Comment:
   Using `.split('\\n')` on the YAML string will include a trailing empty 
element when the dump ends with a newline (common), and it also won’t handle 
other newline conventions. Prefer `splitlines()` (or `splitlines(False)`) here 
to avoid adding an extra blank line and to be newline-agnostic.



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