Skip to content

[backport camel-4.18.x] CAMEL-24001: Fix RestBindingAdvice setting Content-Type on body-less responses#24604

Merged
davsclaus merged 1 commit into
camel-4.18.xfrom
backport/24597-to-camel-4.18.x
Jul 11, 2026
Merged

[backport camel-4.18.x] CAMEL-24001: Fix RestBindingAdvice setting Content-Type on body-less responses#24604
davsclaus merged 1 commit into
camel-4.18.xfrom
backport/24597-to-camel-4.18.x

Conversation

@davsclaus

Copy link
Copy Markdown
Contributor

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.x

Original 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 the ensureHeaderContentType() call.

Bug 2 - Multi-value produces used as Content-Type: ensureHeaderContentType() set the raw comma-separated produces string (e.g. application/json,text/plain) as Content-Type before the isJson/isXml fallback branches had a chance to set a proper single media type. Reordered the priority so isJson/isXml are checked first (setting application/json or application/xml), with the raw produces string only used as a last resort.

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

…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>
@davsclaus davsclaus added the backport indicate that a Pull request is a backport from a fix from the main branch label Jul 11, 2026

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Null-body check moved before ensureHeaderContentType() — prevents spurious Content-Type on 204 No Content responses
  2. ensureHeaderContentType() priority reordered — isJson/isXml checked first (single media type), raw produces string only as last resort
  3. 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).

@davsclaus davsclaus added this to the 4.18.4 milestone Jul 11, 2026
@davsclaus davsclaus self-assigned this Jul 11, 2026
@davsclaus davsclaus added the bug Something isn't working label Jul 11, 2026
@davsclaus davsclaus merged commit 303d52a into camel-4.18.x Jul 11, 2026
3 checks passed
@davsclaus davsclaus deleted the backport/24597-to-camel-4.18.x branch July 11, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport indicate that a Pull request is a backport from a fix from the main branch bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants