a simple method make RestTemplate support parse gzip encoded response just change org.springframework.web.client.MessageBodyClientHttpResponseWrapper old code is
@Override
public InputStream getBody() throws IOException {
return (this.pushbackInputStream != null ? this.pushbackInputStream : this.response.getBody());
}
now code is
@Override
public InputStream getBody() throws IOException {
if (isGzip()) {
return new GZIPInputStream(getRealBody());
}
return getRealBody();
}
private InputStream getRealBody() throws IOException {
return (this.pushbackInputStream != null ? this.pushbackInputStream : this.response.getBody());
}
private boolean isGzip() {
List<String> contentEncodings = getHeaders().get("Content-Encoding");
if (contentEncodings == null || contentEncodings.isEmpty()) {
return false;
}
for (String contentEncoding : contentEncodings) {
if ("gzip".equalsIgnoreCase(contentEncoding)) {
return true;
}
}
return false;
}
Comment From: bclozel
This matter should be supported at the HTTP client library level and configured accordingly. Decoding the response body is not enough, as the component here should also convey the dedicated request headers and react differently depending on the response headers as well.