title: A bit confused about HttpClient[Java] handling gzip responses
body: <p>My application makes a http request to some api service, that service returns a gzipped response. How can I make sure that the response is indeed in gzip format? I'm confused at why after making the request I didn't have to decompress it.</p>
  
  <p>Below is my code:</p>
  
  <pre><code>public static String streamToString(InputStream stream) {
      BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
      StringBuilder sb = new StringBuilder();
      String line;
  
      try {
          while ((line = reader.readLine()) != null) {
              sb.append(line).append("\n");
          }
      } catch (IOException e) {
          logger.error("Error while streaming to string: {}", e);
      } finally {
          try { stream.close(); } catch (IOException e) { }
      }
  
      return sb.toString();
  }
  
  public static String getResultFromHttpRequest(String url) throws IOException { // add retries, catch all exceptions
      HttpClient httpclient = new DefaultHttpClient();
      HttpGet httpGet;
      HttpResponse httpResponse;
      InputStream stream;
  
      try {
          httpGet = new HttpGet(url);
          httpGet.setHeader("Content-Encoding", "gzip, deflate");
          httpResponse = httpclient.execute(httpGet);
          logger.info(httpResponse.getEntity().getContentEncoding());
          logger.info(httpResponse.getEntity().getContent());
          if (httpResponse.getStatusLine().getStatusCode() == 200) {
              stream = httpResponse.getEntity().getContent();
              return streamToString(stream);
          }
      } catch (IllegalStateException e) {
          logger.error("Error while trying to access: " + url, e);
      }
  
      return "";
  }
  </code></pre>
  
  <p>Maybe it is decompressing it automatically, but I would like to see some indication of that at least.</p>