Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/java/feign/codec/StringDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Object decode(Response response, Type type) throws IOException {
return null;
}
if (String.class.equals(type)) {
return Util.toString(body.asReader(Util.UTF_8));
return Util.toString(body.asReader(response.charset()));
}
throw new DecodeException(
response.status(),
Expand Down
19 changes: 19 additions & 0 deletions core/src/test/java/feign/codec/DefaultDecoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import feign.Util;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -45,6 +46,24 @@ void decodesToString() throws Exception {
assertThat(decodedObject.toString()).isEqualTo("response body");
}

@Test
void decodesToStringHonouringContentTypeCharset() throws Exception {
String content = "él pingüino";
byte[] body = content.getBytes(StandardCharsets.ISO_8859_1);
Map<String, Collection<String>> headers = new HashMap<>();
headers.put("Content-Type", Collections.singleton("text/plain; charset=ISO-8859-1"));
Response response =
Response.builder()
.status(200)
.reason("OK")
.headers(headers)
.request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, UTF_8))
.body(new ByteArrayInputStream(body), body.length)
.build();
Object decodedObject = decoder.decode(response, String.class);
assertThat(decodedObject).isEqualTo(content);
}

@Test
void decodesToByteArray() throws Exception {
Response response = knownResponse();
Expand Down