Skip to content

honour requested charset in okhttp response body reader#3441

Open
alhudz wants to merge 1 commit into
OpenFeign:masterfrom
alhudz:okhttp-asreader-charset
Open

honour requested charset in okhttp response body reader#3441
alhudz wants to merge 1 commit into
OpenFeign:masterfrom
alhudz:okhttp-asreader-charset

Conversation

@alhudz

@alhudz alhudz commented Jun 23, 2026

Copy link
Copy Markdown
Contributor
  1. OkHttpClient's response Body.asReader(Charset) ignores the charset argument and delegates to the deprecated asReader(), which returns okhttp's ResponseBody.charStream() (charset taken from Content-Type, defaulting to UTF-8).
  2. decoders read a non-buffered response via response.body().asReader(response.charset()), so the resolved charset is dropped on the okhttp client only; httpclient, hc5 and the core InputStreamBody/ByteArrayBody all decode with the requested charset.

Repro: a text/plain response (no charset parameter) whose body is café as ISO-8859-1 (63 61 66 E9), read via asReader(ISO_8859_1).
Expected: café.
Actual: caf� (decoded as UTF-8).
Fix: decode with the requested charset using new InputStreamReader(asInputStream(), charset), matching the other clients.

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