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

Claus Ibsen commented on CAMEL-26138:
-------------------------------------

PR: https://github.com/apache/camel/pull/28911

h4. 1. chunked=true and a Map, List, POJO or number reply: fixed
The chunked path now converts only the body. A body that is not a stream is 
written as its String form, as a non-chunked reply is. This bug only happens 
when the body is set on the HTTP message itself (a processor or a bean). The 
setBody EIP replaces the HTTP message with a plain message, so it never had the 
bug.

h4. 3. disableStreamCache=true and a form POST: fixed
readBody now reads such a form body as text and keeps it as the body. It does 
this before the headers are read, because Jetty already consumes the stream in 
request.getParameterNames().

h4. 2. mapHttpMessageBody=false: not changed, needs a decision
CAMEL-9833 added the option for proxy routes: "we should not force loading the 
message body". So the intent is "do not read the body eagerly". The lazy read 
in HttpMessage.createBody is what lets a proxy route still forward the body. 
Returning null there would send an empty body in exactly that use case. Today 
the option means: no eager read, no attachments, no Java serialized object, no 
form fields as headers.
Options:
* (a) Keep the behaviour and fix the option description. I recommend this.
* (b) Return null from createBody, as proposed. This is a behaviour change for 
proxy routes and needs an upgrade guide entry.

_Claude Code on behalf of Claus Ibsen (davsclaus)_

> camel-http-common - with chunked=true a Map, List, POJO or number reply is a 
> 200 with an empty body, and mapHttpMessageBody=false still maps the body 
> (jetty, servlet)
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-26138
>                 URL: https://issues.apache.org/jira/browse/CAMEL-26138
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-http-common
>            Reporter: Claus Ibsen
>            Assignee: Claus Ibsen
>            Priority: Major
>             Fix For: 4.24.0
>
>
> Found while adding the catalog body types of jetty and servlet, which share 
> {{DefaultHttpBinding}} and {{HttpMessage}} of camel-http-common (CAMEL-24961, 
> PR #28395).
> h4. 1. With chunked=true (the default) a Map, List, POJO or number reply is a 
> 200 with an empty body
> {{DefaultHttpBinding.doWriteDirectResponse}} (main 2a465aa4814c, line 539) 
> takes {{message.getBody(InputStream.class)}} when the response is chunked. 
> For a Map, List, POJO or number this gives no data (the request stream, 
> already read), so the response is a 200 with an empty body and no error. With 
> {{chunked=false}} the same bodies are written as their String form (line 
> 593). Checked on 4.24.0-SNAPSHOT with a java.net.http client against jetty 
> and servlet consumers (servlet in the Undertow servlet container).
> Proposed: when the body is not a stream or bytes, use the same String 
> fallback as the non-chunked path.
> h4. 2. mapHttpMessageBody=false still maps the request body
> {{DefaultHttpBinding.readRequest}} (line 125) skips {{readBody}} when 
> {{mapHttpMessageBody=false}}, but {{HttpMessage.createBody}} (line 98) reads 
> the body lazily with {{parseBody}} whenever the route asks for it, so the 
> option has no effect on the body the route sees. Checked on 4.24.0-SNAPSHOT 
> with jetty and servlet consumers.
> Proposed: return null from {{HttpMessage.createBody}} when the binding has 
> {{mapHttpMessageBody=false}}.
> h4. 3. With disableStreamCache=true a form POST loses its body
> {{DefaultHttpBinding.readFormUrlEncodedBody}} (line 294) reads the body as a 
> String to map the form fields to headers. With {{disableStreamCache=true}} 
> the body is the raw request stream, so it is consumed: servlet then fails 
> with 500 "UT010029: Stream is closed" and jetty gives the route an empty 
> body. Checked on 4.24.0-SNAPSHOT with jetty and servlet consumers.
> Proposed: with {{disableStreamCache=true}}, keep the read text as the body 
> (or take the form fields from {{request.getParameterMap()}}).
> _Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to