@@ -50,7 +50,7 @@ public class HttpResponse<T> {
5050 @ SuppressWarnings ("unchecked" )
5151 public HttpResponse (org .apache .http .HttpResponse response , Class <T > responseClass ) {
5252 HttpEntity responseEntity = response .getEntity ();
53-
53+
5454 Header [] allHeaders = response .getAllHeaders ();
5555 for (Header header : allHeaders ) {
5656 String headerName = header .getName ().toLowerCase ();
@@ -62,23 +62,24 @@ public HttpResponse(org.apache.http.HttpResponse response, Class<T> responseClas
6262 StatusLine statusLine = response .getStatusLine ();
6363 this .statusCode = statusLine .getStatusCode ();
6464 this .statusText = statusLine .getReasonPhrase ();
65-
65+
6666 if (responseEntity != null ) {
6767 String charset = "UTF-8" ;
68-
68+
6969 Header contentType = responseEntity .getContentType ();
7070 if (contentType != null ) {
7171 String responseCharset = ResponseUtils .getCharsetFromContentType (contentType .getValue ());
7272 if (responseCharset != null && !responseCharset .trim ().equals ("" )) {
7373 charset = responseCharset ;
7474 }
7575 }
76-
76+
7777 try {
7878 byte [] rawBody ;
79+ Long contentLength = responseEntity .getContentLength ();
7980 try {
8081 InputStream responseInputStream = responseEntity .getContent ();
81- if (ResponseUtils .isGzipped (responseEntity .getContentEncoding ())) {
82+ if (ResponseUtils .isGzipped (responseEntity .getContentEncoding ()) && contentLength > 0 ) {
8283 responseInputStream = new GZIPInputStream (responseEntity .getContent ());
8384 }
8485 rawBody = ResponseUtils .getBytes (responseInputStream );
@@ -102,7 +103,7 @@ public HttpResponse(org.apache.http.HttpResponse response, Class<T> responseClas
102103 throw new RuntimeException (e );
103104 }
104105 }
105-
106+
106107 try {
107108 EntityUtils .consume (responseEntity );
108109 } catch (IOException e ) {
@@ -113,7 +114,7 @@ public HttpResponse(org.apache.http.HttpResponse response, Class<T> responseClas
113114 public int getStatus () {
114115 return statusCode ;
115116 }
116-
117+
117118 public String getStatusText () {
118119 return statusText ;
119120 }
0 commit comments