[ 
https://issues.apache.org/jira/browse/CAMEL-12751?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16595611#comment-16595611
 ] 

Bob Paulin commented on CAMEL-12751:
------------------------------------

Based on the description if the goal is to simply make the Producer ignore the 
content-length header by default we might look at 
org.apache.camel.component.http4.HttpProducer.createRequestEntity.  I've 
included 2 proposals in comments
{code:java}
// fallback as input stream
                    if (answer == null) {
                        // force the body as an input stream since this is the 
fallback
                        InputStream is = in.getMandatoryBody(InputStream.class);
                        String length = in.getHeader(Exchange.CONTENT_LENGTH, 
String.class);
                        InputStreamEntity entity = null;


                        //Proposal 1: Remove this conditional and always 
compute length
                        //Proposal 2: Keep conditional and add a second flag 
called allowContentLengthOverride that defaults to false.

                        if (ObjectHelper.isEmpty(length)) {
                            entity = new InputStreamEntity(is, -1);
                        } else {
                            entity = new InputStreamEntity(is, 
Long.parseLong(length));
                        }
                        if (contentType != null) {
                            entity.setContentType(contentType.toString());
                        }
                        answer = entity;
                    }{code}
Agree that ignoring this header as the default gives expected behavior in most 
cases.

> http producer - Ignore content length header
> --------------------------------------------
>
>                 Key: CAMEL-12751
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12751
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-http, camel-http4
>            Reporter: Claus Ibsen
>            Priority: Major
>
> When doing eg REST -> HTTP etc then the REST consumer may populate the 
> message with Content-Length header, which gets propagated to the http 
> producer. We should by default ignore those existing headers and calculate 
> the length in the producer based on the message body, eg if string, byte[] 
> etc which AFAIR does today.
> See nabble
> http://camel.465427.n5.nabble.com/Content-Length-Header-being-used-previous-HTTP-Response-td5813376.html



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to