hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yoram Dayagi (Gmail)" <yor...@gmail.com>
Subject Re: Redirect erases header?
Date Mon, 17 Feb 2014 09:02:27 GMT
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
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message