milamberspace commented on code in PR #6736:
URL: https://github.com/apache/jmeter/pull/6736#discussion_r3730733043


##########
src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/curl/CurlCommandFormatter.java:
##########
@@ -0,0 +1,267 @@
+/*
+ * 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.
+ */
+
+package org.apache.jmeter.protocol.http.curl;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+import org.apache.jmeter.config.Argument;
+import org.apache.jmeter.protocol.http.config.MultipartUrlConfig;
+import org.apache.jmeter.protocol.http.sampler.HTTPSampleResult;
+import org.apache.jmeter.protocol.http.util.HTTPConstants;
+import org.apache.jmeter.protocol.http.util.HTTPFileArg;
+import org.apache.jmeter.testelement.property.JMeterProperty;
+import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jorphan.util.StringUtilities;
+
+/**
+ * Renders an {@link HTTPSampleResult} as a ready-to-run {@code curl} command,
+ * the reverse of what {@link BasicCurlParser} does.
+ *
+ * <p>The generated command targets a POSIX-compatible shell: arguments are
+ * single-quoted and lines are continued with a trailing backslash. It is not
+ * valid {@code cmd.exe} or PowerShell syntax.</p>
+ *
+ * <p>The class has no Swing dependency so it can be reused outside the
+ * View Results Tree (for example by a future "Copy as cURL" sampler 
action).</p>
+ */
+public final class CurlCommandFormatter {
+
+    /** Backslash line continuation followed by indentation, for a POSIX 
shell. */
+    private static final String NEWLINE = " \\\n  "; //$NON-NLS-1$
+
+    private static final String ACCEPT_ENCODING = "Accept-Encoding"; 
//$NON-NLS-1$
+
+    private static final String BOUNDARY = "boundary="; //$NON-NLS-1$
+
+    /**
+     * Headers that must not be reproduced in the curl command: curl generates
+     * them itself, they are connection-specific (hop-by-hop) headers that are
+     * forbidden in HTTP/2 and would make the request fail with a protocol
+     * error, or they are pseudo-headers JMeter adds only for reporting and 
that
+     * never went on the wire (X-LocalAddress).
+     */
+    private static final Set<String> SKIPPED_HEADERS = Set.of(
+            "content-length", //$NON-NLS-1$
+            "connection", //$NON-NLS-1$
+            "keep-alive", //$NON-NLS-1$
+            "proxy-connection", //$NON-NLS-1$
+            "transfer-encoding", //$NON-NLS-1$
+            "upgrade", //$NON-NLS-1$
+            HTTPConstants.HEADER_LOCAL_ADDRESS.toLowerCase(Locale.ROOT));
+
+    /**
+     * Markers JMeter writes into the rendered request body in place of content
+     * it did not keep (a file sent as the body, or a non-repeatable entity).
+     * When present, the body is not the real wire body and cannot be 
reproduced.
+     *
+     * @see org.apache.jmeter.protocol.http.sampler.PostWriter
+     */
+    private static final String[] BODY_PLACEHOLDERS = {

Review Comment:
   `BODY_PLACEHOLDERS` duplicates two literal strings that must stay in sync 
with `PostWriter.java:137,161` and `HTTPHC4Impl.java:1696` (verified they match 
today). There's no shared constant, so if either of those messages is reworded 
later, `containsPlaceholder()` silently stops matching and a placeholder body 
could reach `--data-raw` again — the exact class of bug this PR set out to fix. 
Not blocking, but worth extracting a shared constant at some point.



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