try {
String contentType = response.getHeader(HttpHeaders.CONTENT_TYPE);
if (contentType != null) {
MediaType mediaType = MediaType.parse(contentType);
return new StringResponse(
response.getStatusCode(),
response.getStatusMessage(),
response.getHeaders(),
new String(ByteStreams.toByteArray(response.getInputStream()), mediaType.charset().or(Charsets.UTF_8)));
}
return new StringResponse(
response.getStatusCode(),
response.getStatusMessage(),
response.getHeaders(),
new String(ByteStreams.toByteArray(response.getInputStream()), Charsets.UTF_8));
}