From 84911de1dac5cce3724f8dac0f4ee8ba95be5ee8 Mon Sep 17 00:00:00 2001 From: bunjix Date: Thu, 12 Jul 2012 17:52:14 +0200 Subject: [PATCH] Fix AjaxStatus getError() when gzip is enable --- .../callback/AbstractAjaxCallback.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/com/androidquery/callback/AbstractAjaxCallback.java b/src/com/androidquery/callback/AbstractAjaxCallback.java index 43bc278d..615cd52f 100644 --- a/src/com/androidquery/callback/AbstractAjaxCallback.java +++ b/src/com/androidquery/callback/AbstractAjaxCallback.java @@ -1336,14 +1336,24 @@ private void httpDo(HttpUriRequest hr, String url, Map headers, String message = response.getStatusLine().getReasonPhrase(); String error = null; + HttpEntity entity = response.getEntity(); + InputStream is = null; if(code < 200 || code >= 300){ try{ - HttpEntity entity = response.getEntity(); - byte[] s = AQUtility.toBytes(entity.getContent()); - error = new String(s, "UTF-8"); + + byte[] s = null; + Header encoding = entity.getContentEncoding(); + if(encoding != null && encoding.getValue().equalsIgnoreCase("gzip")) { + is = new GZIPInputStream(entity.getContent()); + s = AQUtility.toBytes(is); + } else + s = AQUtility.toBytes(entity.getContent()); + + error = new String(s, "UTF-8"); AQUtility.debug("error", error); + }catch(Exception e){ AQUtility.debug(e); } @@ -1351,8 +1361,6 @@ private void httpDo(HttpUriRequest hr, String url, Map headers, }else{ - HttpEntity entity = response.getEntity(); - HttpHost currentHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); redirect = currentHost.toURI() + currentReq.getURI(); @@ -1360,7 +1368,6 @@ private void httpDo(HttpUriRequest hr, String url, Map headers, int size = Math.max(32, Math.min(1024 * 64, (int) entity.getContentLength())); OutputStream os = null; - InputStream is = null; try{