Skip to content

Preserve delegate content type for multipart parameters#3382

Open
seonwooj0810 wants to merge 1 commit into
OpenFeign:masterfrom
seonwooj0810:fix/issue-2813-multipart-part-content-type
Open

Preserve delegate content type for multipart parameters#3382
seonwooj0810 wants to merge 1 commit into
OpenFeign:masterfrom
seonwooj0810:fix/issue-2813-multipart-part-content-type

Conversation

@seonwooj0810
Copy link
Copy Markdown
Contributor

Fixes #2813

Problem

When a multipart request contains a POJO/JSON part, DelegateWriter encodes the value through the delegate Encoder (e.g. the Jackson encoder), which correctly sets Content-Type: application/json on the throwaway RequestTemplate. That header was then discarded, and SingleParameterWriter hard-coded Content-Type: text/plain. As a result, JSON parts were emitted as text/plain instead of application/json (see the report in #2813).

Change

  • DelegateWriter now reads the Content-Type produced by the delegate and forwards it to a new SingleParameterWriter.writeWithContentType(output, key, value, contentType) method.
  • When the delegate sets no content type, the writer falls back to the previous text/plain; charset=<charset> behaviour, so plain single parameters are unaffected.
  • The existing write(output, key, value) template method is preserved and simply delegates with a null content type.

Tests

Added feign.form.multipart.DelegateWriterTest:

  • usesContentTypeFromDelegate — asserts a delegate that sets application/json produces Content-Type: application/json (and not text/plain).
  • fallsBackToTextPlainWhenDelegateSetsNoContentType — asserts the text/plain; charset=UTF-8 fallback when the delegate sets no content type.

Test evidence

Ran the form module test suite (and its upstream dependencies) locally:

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 -- feign.form.multipart.DelegateWriterTest
... full feign-core + feign-form suites green ...
BUILD SUCCESS

Verification done: confirmed the hard-coded text/plain still present on master in SingleParameterWriter#write; confirmed no in-flight PR referencing the issue and no active self-claim (maintainer invited a PR with tests on 2026-05-27); fix touches only .java files; full form module test suite passes after the change.

`DelegateWriter` encodes a parameter through the delegate `Encoder` (e.g.
the Jackson encoder), which sets the correct `Content-Type` (such as
`application/json`) on the throwaway `RequestTemplate`. That header was
discarded and `SingleParameterWriter` hard-coded `text/plain`, so JSON
parts of a multipart request were emitted as `text/plain`.

`DelegateWriter` now reads the `Content-Type` produced by the delegate and
passes it through to `SingleParameterWriter.writeWithContentType`, falling
back to `text/plain; charset=<charset>` when the delegate sets no content
type. The previous behaviour for plain single parameters is unchanged.

Fixes OpenFeign#2813

Signed-off-by: seonwoo_jung <79202163+seonwooj0810@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@velo velo left a comment

Choose a reason for hiding this comment

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

Thanks for the focused fix and for adding coverage around the delegated part content type. I cannot approve this while the required CI check is failing.\n\nGate results:\n1) Test coverage: PASS.\n2) Backwards compatibility: PASS.\n3) Security: PASS.\n\nBlocking issue:\n- Required check is currently failing for this PR. Please get the build green before this can be approved or merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong content-type for multipart requests on JSON parts (text/plain instead of application/json)

2 participants