[backport camel-4.18.x] CAMEL-24001: Fix RestBindingAdvice setting Content-Type on body-less responses#24604
Merged
Conversation
…responses RestBindingAdvice.marshal() had two bugs: it set Content-Type on null-body responses (e.g. 204 No Content), and it used raw multi-value produces strings as Content-Type instead of resolving to a single media type. Moved the null-body early-return before ensureHeaderContentType(), and reordered priority so isJson/isXml are checked before the raw produces fallback. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
gnodet
approved these changes
Jul 11, 2026
gnodet
left a comment
Contributor
There was a problem hiding this comment.
Claude Code review on behalf of @gnodet
Clean backport of #24597 — LGTM.
Cherry-pick applies cleanly to camel-4.18.x. The diff is identical to the original fix on main:
- Null-body check moved before
ensureHeaderContentType()— prevents spurious Content-Type on 204 No Content responses ensureHeaderContentType()priority reordered — isJson/isXml checked first (single media type), rawproducesstring only as last resort- 3 test cases covering both bugs + the happy path
No upgrade guide entry needed on the maintenance branch (per project guidelines, those go on main).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #24597
Claude Code on behalf of davsclaus
Cherry-pick of #24597 onto
camel-4.18.x.Original PR: #24597 - CAMEL-24001: Fix RestBindingAdvice setting Content-Type on body-less responses
Original author: @davsclaus
Target branch:
camel-4.18.xOriginal description
Fixes two bugs in
RestBindingAdvice.marshal()related to Content-Type handling:Bug 1 - Content-Type set on body-less responses:
ensureHeaderContentType()was called before the null-body check, so responses with no body (e.g. 204 No Content) got a spurious Content-Type header. Moved the null-body check to before theensureHeaderContentType()call.Bug 2 - Multi-value
producesused as Content-Type:ensureHeaderContentType()set the raw comma-separatedproducesstring (e.g.application/json,text/plain) as Content-Type before theisJson/isXmlfallback branches had a chance to set a proper single media type. Reordered the priority soisJson/isXmlare checked first (settingapplication/jsonorapplication/xml), with the rawproducesstring only used as a last resort.Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com