title: Content-Length header missing for Spring RestTemplate Gzip response
body: <p>I am using Spring Boot to integrate to a third party which can provide gzipped responses and I want to log the size of the compressed response body vs the decompressed so we can audit for billing etc.</p>
  
  <p>I'm using RestTemplate.exchange to make the GET request and the response is coming back correctly however I am unable to retrieve the Content-Length header in the response.</p>
  
  <p>I know that the third party are sending it back because I can see it when I make the same request using Curl:</p>
  
  <pre><code>HTTP/1.1 200 OK
  Date: Mon, 04 Feb 2019 15:40:10 GMT
  Server: Apache
  Vary: Accept-Encoding
  Content-Encoding: gzip
  Content-Length: 558
  Connection: close
  Content-Type: application/json
  </code></pre>
  
  <p>This is my Java code making the request and logging the lengths:</p>
  
  <pre><code>final ResponseEntity&lt;String&gt; responseEntity = restTemplate.exchange(url, GET, entity, String.class);
  final String body = responseEntity.getBody();
  LOG.info("Payload sizes: compressed={}, uncompressed={}", responseEntity.getHeaders().getContentLength(), body.length());
  </code></pre>
  
  <p>For the request headers I am setting 'Accept-Encoding: gzip,deflate' as per the documentation for the third party. However when I get the response the call to getContentLength() just returns -1. I've done a lot of searching around on this and tried using a ClientHttpRequestInterceptor but no joy.</p>
  
  <p>Anybody ever had the same issues? </p>