On Fri, 2019-06-21 at 00:04 +0000, Krishna Sankaran wrote: > I am using the following java snippet for a HEAD request. The request > gets redirected couple of times, a 301 followed by 302 and dinally > gets a 200.When i use the following code snippet, i get the status as > 200 OK, however all the header fields are from the 1st response > (301). The Content-Length header is present in the last response, but > i don't see that in the header's received by the code. Is there a > knob to get the last header or all headers? > > private static final String SAMPLE_URL = " > https://www.dropbox.com/s/<something>/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()); > } > } > > It returns the code as 200 OK, but the Content-Type is incorrect, > even > the > HTTP/1.1 200 OK <<< Status is 200 Server: nginx Date: Thu, 20 Jun > 2019 02:22:58 GMT Content-Type: text/html; charset=utf-8 << Content > type is char <<<< Content-Length > is missing!!!!! > > curl -I https://www.dropbox.com/s//test_out4.mp4 << Curl works > correctly > > > > HTTP/1.1 301 Moved Permanently <<< Status 301 Server: nginx > Date: Thu, 20 Jun 2019 02:20:50 GMT Content-Type: text/html; > charset=utf-8 <<< Content type text Connection: keep-alive > .... > HTTP/1.1 302 Found << second redirect Server: nginx > Date: Thu, 20 Jun 2019 02:36:03 GMT > Content-Type: text/html; charset=utf-8 > .... > HTTP/1.1 200 OK <<< Status finally 200 Server: nginx > Date: Thu, 20 Jun 2019 02:36:04 GMT > Content-Type: video/mp4 << content type correct > Content-Length: 92894175 << length correct Connection: keep-alive > >
Krishna I _suppose_ this is due automatic content compression used by HttpClient per default. This can be easy to tell if you turn on HttpClient context / wire logging. Try disabling automatic content compression. --- CloseableHttpClient client = HttpClients.custom() .disableContentCompression() .build(); --- Oleg --------------------------------------------------------------------- To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org For additional commands, e-mail: httpclient-users-h...@hc.apache.org