This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-3.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.18.x by this push:
new 6bb742f9e58 CAMEL-18589: camel-http-common - Fix DefaultHttpBinding
extract headers to deal better with headers with multiple keys. Thanks to
Praveen Prabhu for the patch.
6bb742f9e58 is described below
commit 6bb742f9e58b7d97ac6195f5fb2742396d3b52d5
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Oct 9 11:24:52 2022 +0200
CAMEL-18589: camel-http-common - Fix DefaultHttpBinding extract headers to
deal better with headers with multiple keys. Thanks to Praveen Prabhu for the
patch.
---
.../camel/http/common/DefaultHttpBinding.java | 22 +++++++++++++++-------
.../servlet/rest/RestServletContentTypeTest.java | 2 +-
2 files changed, 16 insertions(+), 8 deletions(-)
diff --git
a/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
b/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
index 9fa5625c01b..4d0033c5ae2 100644
---
a/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
+++
b/components/camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
@@ -157,20 +157,28 @@ public class DefaultHttpBinding implements HttpBinding {
Map<String, Object> headers = message.getHeaders();
- //apply the headerFilterStrategy
Enumeration<?> names = request.getHeaderNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
- String value = request.getHeader(name);
- // use http helper to extract parameter value as it may contain
multiple values
- Object extracted = HttpHelper.extractHttpParameterValue(value);
// mapping the content-type
if (name.equalsIgnoreCase("content-type")) {
name = Exchange.CONTENT_TYPE;
}
- if (headerFilterStrategy != null
- &&
!headerFilterStrategy.applyFilterToExternalHeaders(name, extracted,
message.getExchange())) {
- HttpHelper.appendHeader(headers, name, extracted);
+ // some implementations like Jetty might return unique header
names, while some others might not.
+ // Since we are going to call request.getHeaders() to get all
values for a header name,
+ // we only need to process a header once.
+ if (!headers.containsKey(name)) {
+ Enumeration<String> values = request.getHeaders(name);
+ while (values.hasMoreElements()) {
+ String value = values.nextElement();
+ // use http helper to extract parameter value as it may
contain multiple values
+ Object extracted =
HttpHelper.extractHttpParameterValue(value);
+ //apply the headerFilterStrategy
+ if (headerFilterStrategy != null
+ &&
!headerFilterStrategy.applyFilterToExternalHeaders(name, extracted,
message.getExchange())) {
+ HttpHelper.appendHeader(headers, name, extracted);
+ }
+ }
}
}
diff --git
a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletContentTypeTest.java
b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletContentTypeTest.java
index 5d46a440070..008884c445b 100644
---
a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletContentTypeTest.java
+++
b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletContentTypeTest.java
@@ -39,7 +39,7 @@ public class RestServletContentTypeTest extends
ServletCamelRouterTestSupport {
null);
WebResponse response = query(req, false);
- assertEquals("{ \"status\": \"ok\" }", response.getText());
+ assertEquals(415, response.getResponseCode());
}
@Test