String charset = m.getResponseCharSet();
if (charset == null) charset = "UTF-8";
// check for deflate and gzip compression
Header h = m.getResponseHeader("content-encoding");
String encoding = (h == null) ? null : h.getValue();
if (encoding != null && encoding.equals("deflate")) {
byte[] body = m.getResponseAsBytes();
InputStream is = new BufferedInputStream(new InflaterInputStream(new ByteArrayInputStream(body)), 10000);
return readContents(is, charset, maxKbytes);