title: When HTTP redirect occurs, apache HttpClient returns header from first response and not the last response
body: <p>This is my java program</p>
  
  <pre><code>private static final String SAMPLE_URL = "https://www.dropbox.com/s/&lt;something&gt;/test_out4.mp4";
  
  public static void main(String[] args) throws IOException, URISyntaxException {
      HttpClient client = HttpClientBuilder.create().build();
      HttpHead request = new HttpHead(new URI(SAMPLE_URL));
      HttpResponse response = client.execute(request);
      System.out.println(response.getStatusLine());
      for (Header header : response.getAllHeaders()) {
          System.out.println(header.getName() + ": " + header.getValue());
      }
  }
  </code></pre>
  
  <p>See a snippet of the output of the java program. The status line says it is HTTP/1.1 200 OK. However the header fields that are printed doesn't match what i get when i run curl manually. It seems to take the header values from the first response and not from the last response. Even more important Content Length field which is present in the last response is not set the response structure.</p>
  
  <p><code>HTTP/1.1 200 OK   &lt;&lt;&lt; Status is 200
      Server: nginx
      Date: Thu, 20 Jun 2019 02:22:58 GMT
      Content-Type: text/html; charset=utf-8  &lt;&lt; Content type is char</code></p>
  
  <p>When i run curl the output is correct. Is there any setting in HttpClient to return the most recent headers?</p>
  
  <p><code>curl -I  https://www.dropbox.com/s/&lt;something&gt;/test_out4.mp4
     HTTP/1.1 301 Moved Permanently   &lt;&lt;&lt; Status 301
     Server: nginx
     Date: Thu, 20 Jun 2019 02:20:50 GMT
     Content-Type: text/html; charset=utf-8   &lt;&lt;&lt; Content type text
     Connection: keep-alive</code></p>
  
  <p>....</p>
  
  <p><code>HTTP/1.1 302 Found  &lt;&lt; second redirect
     Server: nginx
     Date: Thu, 20 Jun 2019 02:36:03 GMT
     Content-Type: text/html; charset=utf-8</code></p>
  
  <p>....</p>
  
  <p><code>HTTP/1.1 200 OK  &lt;&lt;&lt; Status finally 200
     Server: nginx
     Date: Thu, 20 Jun 2019 02:36:04 GMT
     Content-Type: video/mp4   &lt;&lt; content type correct
     Content-Length: 92894175  &lt;&lt; length correct
     Connection: keep-alive</code></p>