You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Kevin Brooks (JIRA)" <ji...@apache.org> on 2018/03/22 22:01:00 UTC
[jira] [Created] (CAMEL-12395) HttpProducer.populateResponse
dropping headers (cookies)
Kevin Brooks created CAMEL-12395:
------------------------------------
Summary: HttpProducer.populateResponse dropping headers (cookies)
Key: CAMEL-12395
URL: https://issues.apache.org/jira/browse/CAMEL-12395
Project: Camel
Issue Type: Bug
Affects Versions: 2.20.2
Reporter: Kevin Brooks
When a host responds with multiple headers with the same key, with different values, the HttpProducer overwrites the value, effectively last-in-wins, extracted problem code below
{code:java}
protected void populateResponse(Exchange exchange, HttpRequestBase httpRequest, HttpResponse httpResponse,
Message in, HeaderFilterStrategy strategy, int responseCode) throws IOException, ClassNotFoundException {
...
// propagate HTTP response headers
Header[] headers = httpResponse.getAllHeaders();
Map<String, List<String>> m = new HashMap<String, List<String>>();
for (Header header : headers) {
String name = header.getName();
String value = header.getValue();
m.put(name, Collections.singletonList(value)); //This is the problem
if (name.toLowerCase().equals("content-type")) {
name = Exchange.CONTENT_TYPE;
exchange.setProperty(Exchange.CHARSET_NAME, IOHelper.getCharsetNameFromContentType(value));
}
// use http helper to extract parameter value as it may contain multiple values
Object extracted = HttpHelper.extractHttpParameterValue(value);
if (strategy != null && !strategy.applyFilterToExternalHeaders(name, extracted, exchange)) {
HttpHelper.appendHeader(answer.getHeaders(), name, extracted);
}
}
// handle cookies
if (getEndpoint().getCookieHandler() != null) {
//if host responded with multiple Set-Cookie headers, only last cookie is presented
getEndpoint().getCookieHandler().storeCookies(exchange, httpRequest.getURI(), m);
}
...
{code}
A simple fix ->
{code:java}
...
for (Header header : headers) {
String name = header.getName();
String value = header.getValue();
List<String> values = m.computeIfAbsent(name, k -> new ArrayList<>()).add(value);
...
{code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)