[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-928?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12852288#action_12852288
 ] 

Oleg Kalnichevski commented on HTTPCLIENT-928:
----------------------------------------------

There is absolutely no need to duplicate the functionality of 
DefaultRedirectHandler. What is wrong with just extending the class?

---
DefaultHttpClient httpclient = new DefaultHttpClient();
RedirectHandler redirectHandler = new DefaultRedirectHandler() {

    public URI getLocationURI(
            final HttpResponse response, final HttpContext context) throws 
ProtocolException {
        URI uri = super.getLocationURI(response, context);
        System.out.println("----------------------------------------");
        System.out.println("Redirected to: " + uri);
        System.out.println("----------------------------------------");
        return uri;
    }
    
};

httpclient.setRedirectHandler(redirectHandler);

HttpHost target = new HttpHost("www.google.com", 80, "http");
HttpGet httpget = new HttpGet("/");

HttpResponse response = httpclient.execute(target, httpget);

System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
System.out.println("----------------------------------------");
HttpEntity entity = response.getEntity();
if (entity != null) {
    entity.consumeContent();
}
---

Oleg

> Can't get list of redirect locations
> ------------------------------------
>
>                 Key: HTTPCLIENT-928
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-928
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>          Components: HttpClient
>    Affects Versions: 4.0.1
>            Reporter: Ryan Stewart
>
> HttpClient does a great job of following redirects, but afterward there 
> doesn't seem to be any way to see the URLs that it followed in the redirect 
> chain. They are stored internally by the DefaultRedirectHandler in the 
> HttpContext in an attribute named "http.protocol.redirect-locations", but the 
> RedirectLocations object that contains them stores them in a Set, so there's 
> no way of knowing in what order the URLs were visited.
> Here's an example of why I need it:
> 1) Use HttpClient to retrieve http://foo.com
> 2) http://foo.com returns a 301 redirect to http://foo.com/bar, so HttpClient 
> follows the redirect and returns the page to me
> 3) http://foo.com/bar refers to a relative resource like "baz.html".
> That relative resource should resolve to "http://foo.com/bar/baz.html";. I 
> only know that, though, if I can look at the redirect URL that HttpClient got 
> in step 2. Currently, I don't seem to be able to do that.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to