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 Subashini S <s_...@yahoo.com> on 2008/09/16 20:56:33 UTC

blank location in redirected response

 
Hi,
 
I’ve come across a scenario where the location:
 
http://www.nwsource.com/travel/scr/tf_destination.cfm? When requested in IE browser comes back with the following response code:
 
GET http://www.nwsource.com/travel/scr/tf_destination.cfm? 302 Moved Temporarily to '' 
When the successive requests were studied, IE browser seems to make requests as follows: 
 




Request

Response code

Location


GET http://www.nwsource.com/travel/scr/tf_destination.cfm?

302

Moved Temporarily to ''


GET http://www.nwsource.com/travel/scr/

302

Moved Temporarily to /travel/


GET http://www.nwsource.com/travel/

301

Moved Permanently to http://www.nwsource.com/travel
 
So finally the browser renders the page: http://www.nwsource.com/travel
 
However with httpclient, when the first request is made, the response  header comes back with blank value for location. 




GET http://www.nwsource.com/travel/scr/tf_destination.cfm?

302

Moved Temporarily to ''
 
Whenever there is a redirection to a relative url, the url is absolutized and fetched. In our case however, the redirected url happens to be a blank string and hence when absolutizing, the original url is returned. And hence, goes into infinite redirection.
 
            if (redirectUri.isRelativeURI()) {
                if (this.params.isParameterTrue(HttpClientParams.REJECT_RELATIVE_REDIRECT)) {
                    LOG.warn("Relative redirect location '" + location + "' not allowed");
                    return false;
                } else { 
                    //location is incomplete, use current values for defaults
                    LOG.debug("Redirect URI is not absolute - parsing as relative");
                    redirectUri = new URI(currentUri, redirectUri);
                }
The control comes to the else part of this snippet in 
org.apache.commons.httpclient.HttpMethodDirector class
 and we are getting the following output:
Narrowly avoided an infinite loop in execute 
caught org.apache.commons.httpclient.RedirectException: Maximum redirects (100) exceeded 
 
Has anyone come across a similar situation where the redirect location is blank. If so is it possible to emulate browser behaviour without a code change in httpclient?
 
Thanks in advance,
Subashini