Skip to content

Instantly share code, notes, and snippets.

@vovkab
Created August 21, 2015 18:25
Show Gist options
  • Save vovkab/b9c8ffa86d97e685d3cb to your computer and use it in GitHub Desktop.
Save vovkab/b9c8ffa86d97e685d3cb to your computer and use it in GitHub Desktop.
private String decodeBody(Response response) throws IOException {
final ResponseBody body = response.body();
if (body == null) return null;
if (isZipped(response)) {
return unzip(response.body());
} else {
return body.string();
}
}
private boolean isZipped(Response response) {
return "gzip".equalsIgnoreCase(response.header("Content-Encoding"));
}
private String unzip(ResponseBody body) {
try {
GzipSource responseBody = new GzipSource(body.source());
return Okio.buffer(responseBody).readUtf8();
} catch (IOException e) {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment