gnodet-bot commented on code in PR #27787:
URL: https://github.com/apache/camel/pull/27787#discussion_r4267355958


##########
components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java:
##########
@@ -340,12 +348,30 @@ public void onDone(Exchange exchange1) {
     }
 
     private static void applyHeader(HttpUriRequest httpRequest, String key, 
List<String> multiValues, String prev) {
-        // add the value(s) as a http request header
+        // add the value(s) as http request header(s), one header line per 
value
+        if (multiValues != null) {
+            for (String value : multiValues) {
+                httpRequest.addHeader(key, value);
+            }
+        } else if (prev != null) {
+            httpRequest.addHeader(key, prev);
+        }
+    }
+
+    private static boolean isSentAsOneJoinedHeader(Object value) {
+        if (value instanceof Iterator || value instanceof Stream
+                || (value instanceof Iterable && !(value instanceof 
Collection))) {
+            return true;
+        }
+        Class<?> type = value.getClass();
+        return type.isArray() && type.getComponentType().isPrimitive()
+                && type != byte[].class && type != char[].class;
+    }
+
+    private static void applyJoinedHeader(HttpUriRequest httpRequest, String 
key, List<String> multiValues, String prev) {
+        // two or more values are sent as one header in the form [a, b], one 
value as it is
         if (multiValues != null) {
-            // use the default toString of a ArrayList to create in the form 
[xxx, yyy]
-            // if multi valued, for a single value, then just output the value 
as is
-            String s = multiValues.size() > 1 ? multiValues.toString() : 
multiValues.get(0);
-            httpRequest.addHeader(key, s);
+            httpRequest.addHeader(key, multiValues.toString());

Review Comment:
   ⚠️ **Regression: single-element joined headers now produce `[x]` instead of 
`x`**
   
   `applyJoinedHeader` calls `multiValues.toString()` unconditionally, but 
`ArrayList.toString()` on a single-element list produces `[x]`, not `x`.
   
   The old `applyHeader` had a guard:
   ```java
   String s = multiValues.size() > 1 ? multiValues.toString() : 
multiValues.get(0);
   ```
   
   All four types routed here by `isSentAsOneJoinedHeader` — primitive arrays 
(`int[]`, `long[]`, …), `Iterator`, `Stream`, and non-Collection `Iterable` — 
are therefore regressed when they contain exactly one element. The method 
comment above says *"one value as it is"* but the implementation does the 
opposite.
   
   Also note the discrepancy: the new method comment at the start of this block 
reads *"two or more values are sent as one header in the form `[a, b]`, one 
value as it is"* — but the code sends even a single value in `[x]` form.
   
   ```suggestion
               httpRequest.addHeader(key, multiValues.size() > 1 ? 
multiValues.toString() : multiValues.get(0));
   ```



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