commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject RE: [httpclient]: Q about HttpMultiClient and redirects
Date Tue, 07 May 2002 14:10:58 GMT
Yep, I need to fix this and its actually next on my list.  

There are some other problems with this code.  Namely, we really can't deal
with all 303 responses *inside* HttpClient or HttpMultiClient, it may have
to pass the 303 response back to the caller in order to do the right thing.
The 303 response indicates that the client should use a GET request for the
new location instead of using the same method as the original request.  Note
that most browsers currently get this wrong and always send a GET in
response to a 302 result.  Yahoo! event *requires* that the client violate
the HTTP specification and send a GET in response to a 302 redirect of a
POST method in order to get logged in. 

Neither HttpClient nor HttpMultiClient have the ability to change the method
because the 'method' is actually a Java object that got passed in to the
executeMethod() method.  So, if we get a 303 result in response to anything
besides a GET method we have no choice but to send the 303 result back to
the caller and have them generate a new GET request for the new location.
This sucks, but given the current architecture I don't see any way around

To deal with Yahoo! we have to pass back the 405 Method Not Allowed response
and have the caller guess that it should send back a GET instead of the
POST.  Againk this sucks, but I don't see any other alternative right now.

Marc Saegesser 

> -----Original Message-----
> From: otisg []
> Sent: Monday, May 06, 2002 5:54 PM
> To:
> Subject: [httpclient]: Q about HttpMultiClient and redirects
> Hello,
> Is there a way to 'catch' redirected URLs when using HttpMultiClient?
> It seems like this block of code, which is a part of executeMethod
> method, always gets executed if the status code matches.
> Wouldn't it be useful to have a setFollowRedirects(boolean) method in
> HttpMultiClient, as well as a matching getFollowRedirects() 
> method? If I
> were to use HttpMultiClient, and I'd like to, I would need 
> this, since I
> need to differentiate between URLs that return a 200 OK, and 
> one of the
> resource moved codes.
> if (status == 301 || status == 302 || 
> status == 303 || status == 307)
> {
> Header header = method.getResponseHeader("Location");
> String url = header.getValue();
> if (url == null)
> {
> log.error("HttpMultiClient.executeMethod: Received redirect without
> Location header.");
> throw new HttpException("Received redirect without Location header.");
> }
> method.recycle();
> method.setUrl(url);
> return executeMethod(method);
> }
> I can provide patch....just let me know, since I can't commit to
> commons.
> Thanks,
> Otis
> _______________________________________________________________
> Sign up for FREE iVillage newsletters 
> <> .
> From health and pregnancy to shopping and relationships, iVillage
> has the scoop on what matters most to you. 

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message