Skip to content

encode string request body with utf-8 not the platform default#3442

Open
alhudz wants to merge 1 commit into
OpenFeign:masterfrom
alhudz:request-body-utf8
Open

encode string request body with utf-8 not the platform default#3442
alhudz wants to merge 1 commit into
OpenFeign:masterfrom
alhudz:request-body-utf8

Conversation

@alhudz

@alhudz alhudz commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Repro: build a body with Request.Body.create(String) on a JVM whose default charset is not UTF-8 (-Dfile.encoding=ISO-8859-1) and send a non-ASCII payload such as "é"; the bytes on the wire are the ISO-8859-1 encoding, not the UTF-8 the rest of feign and the declared Content-Type assume.
Cause: create(String) encodes with data.getBytes(), the platform-default charset, and leaves the body encoding null so it is flagged binary. Every other body path defaults to UTF-8 (RequestTemplate.body(String) and the create(String, Charset) overload), so the result is deployment-dependent and the dropped charset means asString()/charset() cannot recover the text.
Fix: delegate to create(data, UTF_8) so the bytes are deterministic UTF-8 and the charset is recorded, matching the sibling overload.

Signed-off-by: Alhuda Khan <al.hudz.k@gmail.com>
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.

1 participant