allthingssecurity opened a new pull request, #27690:
URL: https://github.com/apache/camel/pull/27690

   # Description
   
   [CAMEL-25547](https://issues.apache.org/jira/browse/CAMEL-25547)
   
   `KnativeHttpProducer.process` copied each message header to the request as 
`entry.getValue().toString()`. For a collection that is the `toString()` of the 
collection, so a header holding `List.of("a", "b")` was sent as the single line 
`X-Test: [a, b]`, and a `String[]` as `[Ljava.lang.String;@...`. The Knative 
HTTP consumer (like the other HTTP consumers) maps a request header that occurs 
more than once to a List, so a route forwarding such a request to a Knative 
sink sent corrupted values without an error. This is the same defect as 
CAMEL-25526 in camel-vertx-http.
   
   The reply of the consumer had a related defect: 
`KnativeHttpConsumer.toHttpResponse` iterated the values of a header but called 
`response.putHeader(key, headerValue)` for each of them, which replaces the 
header, so only the last value was sent.
   
   Now both places use the same value handling as the camel-vertx-http fix 
(CAMEL-25526): a value that is an `Iterable` or an `Object[]` is iterated as 
camel-http does (`ObjectHelper.createIterator` without a delimiter and 
`HttpUtil.applyHeader`, which applies the header filter per value and skips 
null values) and all the values of the header are added at once. Every other 
value is one header, converted with `tc.convertTo(String.class, value)` after 
the header filter. A note is added to the existing camel-knative section of the 
4.23 upgrade guide.
   
   What changes for a single value:
   - A String (also one with commas) and a number are sent as before.
   - A `byte[]` (a Kafka record header, for example) is now sent as one String. 
On main the producer sent its `toString()` (`[B@1dc9f5ad`) and the reply of the 
consumer iterated it and kept the last byte as a number (`99` for `abc`). 
`byte[]` and the other primitive arrays are deliberately not iterated.
   - A header with a null value is not sent, as before: 
`KnativeHttpHeaderFilterStrategy` (a `DefaultHeaderFilterStrategy`, fixed in 
both classes) filters null values before the value is read, so the `toString()` 
on main could not fail on null. Nothing changes there, and I added no test for 
it because it passes on main.
   
   Tests:
   - New `KnativeHttpMultiValueHeaderTest` (the test HTTP server and 
platform-http setup of `KnativeHttpTest`), 7 tests: the producer with a List 
header, an array header, a List with a null element, a `byte[]` and a String 
with a comma; the reply of a consumer route with a List header (and a 
single-value header next to it) and with a `byte[]` header.
   - On main six of the seven fail: `Expecting actual: ["[a, b]"] to contain 
exactly (and in same order): ["a", "b"]`, `["[Ljava.lang.String;@..."]`, `["[a, 
null, b]"]` and `["[B@..."]` (expected `["abc"]`) for the producer, `["b"]` and 
`["99"]` (expected `["abc"]`) for the reply. The String test passes on main 
too; it is kept because it pins that the value is not split at a delimiter.
   - With the change: camel-knative-http 183 tests, 0 failures.
   
   Not changed here: the producer keeps only the last value of a response 
header that occurs more than once. Making that a List would change the type of 
such a header for existing routes, so I left it out of this fix; I can follow 
up if you want it.
   
   Found by comparing the producer with its camel-vertx-http sibling, with a 
small Lean 4 model of the header copy (main is proved wrong for every list 
value in the producer and for every list of two or more values in the reply; 
the fix equals camel-http's behaviour for every value of the model (a String or 
a list of Strings) and sends the same line as before for every String). I then 
reproduced it with the producer and the consumer.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
     (I built and tested camel-knative-http, including the formatter and 
import-sort plugins. I did not run the full root build.)
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
     This PR was prepared with Claude Code (Claude Opus 5.5). The commit 
carries a `Co-Authored-By` trailer.
   
   _Claude Code on behalf of allthingssecurity_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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