davsclaus commented on code in PR #29103:
URL: https://github.com/apache/camel/pull/29103#discussion_r4457655910
##########
components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java:
##########
@@ -521,7 +524,14 @@ public HttpResponse toNettyResponse(Message message,
NettyHttpConfiguration conf
}
if (buffer == null) {
// fallback to byte array as last resort
- byte[] data = message.getBody(byte[].class);
+ byte[] data;
+ try {
+ data = message.getBody(byte[].class);
+ } catch (TypeConversionException e) {
Review Comment:
Dropped the catch in 0d04dd5ad4e6, after merging main (with #29111). The
`List` reply still gives `200 [a, b]` through the `String` fallback.
`NettyHttpReplyBodyTest#testFailingByteArrayConverterReply` adds a converter to
`byte[]` that throws (`IOException("disk on fire")`) and expects a 500, as on
main. It failed with the catch (`expected: <500> but was: <200>`).
_Claude Code on behalf of Claus Ibsen (davsclaus)_
##########
components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java:
##########
@@ -511,7 +512,9 @@ public HttpResponse toNettyResponse(Message message,
NettyHttpConfiguration conf
if (response == null) {
if (body instanceof ByteBuf byteBuf) {
- buffer = byteBuf;
+ // the request body (with disableStreamCache) is released when
the exchange is done, so a reply that
+ // sends it back must write a reference of its own, as writing
the response releases the buffer too
+ buffer = isRequestBody(message, byteBuf) ?
byteBuf.retainedDuplicate() : byteBuf;
Review Comment:
Fixed in 0d04dd5ad4e6. The reply now writes a plain `duplicate()` of the
request buffer, and the extra reference (`retain()` on the request buffer) is
taken as the last step of `toNettyResponse`, once the headers are set. When
building the response fails, no reference is taken.
`NettyHttpReplyBodyTest#testEchoRequestBodyWithBadHeaderWithDisableStreamCache`
echoes with `disableStreamCache=true` and sets the header `X-Bad: line
one\nline two`. It expects a 500 and a request buffer `refCnt` of 0, three
times. Without the change the `refCnt` stayed at 1.
_Claude Code on behalf of Claus Ibsen (davsclaus)_
--
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]