You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by "Yoram Dayagi (Gmail)" <yo...@gmail.com> on 2014/02/16 16:06:32 UTC
Redirect erases header?
Hi
I’m using HttpAsyncClient to execute an async request.
I noticed that when requesting a GET request for a URL that redirects to another, a header I put in the request ("Range: bytes=0-1000") is ignored and all content is returned in the response.
Notes:
1. When accessing directly the redirected URL the execution is as expected (only first 1000 bytes are returned)
2. The response of the original URL doesn’t contain a header "Accept-Ranges: bytes”, where as the response of the redirected URL does contain this header.
How can I overcome this problem?
--
Yoram Dayagi (Gmail)
Sent with Airmail
Re: Redirect erases header?
Posted by "Yoram Dayagi (Gmail)" <yo...@gmail.com>.
Hi
Found the answer: when building the HttpAsyncClient set a redirect strategy and add the appropriate header:
HttpAsyncClientBuilder builder = HttpAsyncClients.custom();
builder.setRedirectStrategy(new DefaultRedirectStrategy() {
@Override
public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
HttpUriRequest redirectRequest = super.getRedirect(request, response, context);
// copy “Range" headers, if exist
Header[] rangeHeaders = request.getHeaders(“Range");
if (rangeHeaders != null) {
for (Header header : rangeHeaders) {
redirectRequest.addHeader(header);
}
}
return redirectRequest;
}
});
Thanks,
--
Yoram Dayagi (Gmail)
Sent with Airmail
On February 16, 2014 at 5:06:34 PM, Yoram Dayagi (Gmail) (yoramd@gmail.com) wrote:
Hi
I’m using HttpAsyncClient to execute an async request.
I noticed that when requesting a GET request for a URL that redirects to another, a header I put in the request ("Range: bytes=0-1000") is ignored and all content is returned in the response.
Notes:
1. When accessing directly the redirected URL the execution is as expected (only first 1000 bytes are returned)
2. The response of the original URL doesn’t contain a header "Accept-Ranges: bytes”, where as the response of the redirected URL does contain this header.
How can I overcome this problem?
--
Yoram Dayagi (Gmail)
Sent with Airmail