Changing DefaultGzipDecoder's charset to UTF-8 (#250)

This commit is contained in:
kingj
2019-12-17 00:29:21 +09:00
committed by Spencer Gibb
parent d5c176c5f4
commit 68689182be
3 changed files with 25 additions and 5 deletions

View File

@@ -20,12 +20,12 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.zip.GZIPInputStream;
import feign.FeignException;
import feign.Response;
import feign.Util;
import feign.codec.Decoder;
import org.springframework.cloud.openfeign.encoding.HttpEncoding;
@@ -72,7 +72,7 @@ public class DefaultGzipDecoder implements Decoder {
try (GZIPInputStream gzipInputStream = new GZIPInputStream(
response.body().asInputStream());
BufferedReader reader = new BufferedReader(
new InputStreamReader(gzipInputStream, Util.ISO_8859_1))) {
new InputStreamReader(gzipInputStream, StandardCharsets.UTF_8))) {
String outputString = "";
String line;
while ((line = reader.readLine()) != null) {

View File

@@ -90,6 +90,18 @@ public class DefaultGzipDecoderTests extends FeignClientFactoryBean {
assertThat(hello).as("null hello didn't match").isEqualTo(null);
}
@Test
public void testCharsetDecompress() {
ResponseEntity<Hello> response = testClient().getUtf8Response();
assertThat(response).as("response was null").isNotNull();
assertThat(response.getStatusCode()).as("wrong status code")
.isEqualTo(HttpStatus.OK);
Hello hello = response.getBody();
assertThat(hello).as("hello was null").isNotNull();
assertThat(hello).as("utf8 hello didn't match")
.isEqualTo(new Hello("안녕하세요 means Hello in Korean"));
}
private static class Hello {
private String message;
@@ -136,6 +148,9 @@ public class DefaultGzipDecoderTests extends FeignClientFactoryBean {
@GetMapping("/nullGzipResponse")
ResponseEntity<Hello> getNullResponse();
@GetMapping("/utf8Response")
ResponseEntity<Hello> getUtf8Response();
}
@Configuration(proxyBeanMethods = false)
@@ -154,6 +169,11 @@ public class DefaultGzipDecoderTests extends FeignClientFactoryBean {
return ResponseEntity.ok(null);
}
@Override
public ResponseEntity<Hello> getUtf8Response() {
return ResponseEntity.ok(new Hello("안녕하세요 means Hello in Korean"));
}
}
}