urunni88 commented on code in PR #27787:
URL: https://github.com/apache/camel/pull/27787#discussion_r4267531703
##########
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:
Thanks for checking. HttpUtil.applyHeader only creates the list when a
second value arrives, so multiValues is either null or has two or more entries;
a single value goes through prev and is sent as it is. So the method comment is
accurate, and the [x] case does not happen. I added
testSingleElementIntArrayIsOneHeader to pin this (int[] {7} is sent as 7).
--
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]