if (redirectCount++ >= 100)
{
fail("Possible infinite redirect detected. Bailing out.");
}
Url newUrl = Url.parse(lastResponse.getRedirectLocation(),
Charset.forName(request.getCharacterEncoding()));
if (isExternalRedirect(lastRequest.getUrl(), newUrl))
{
// we can't handle external redirects here
// just bail out here and let the user's test code
// check #assertRedirectUrl
return true;
}
if (newUrl.isAbsolute())
{
request.setUrl(newUrl);
final String protocol = newUrl.getProtocol();
if (protocol != null)
{
request.setScheme(protocol);
}
request.setSecure("https".equals(protocol));
if (newUrl.getHost() != null)
{
request.setServerName(newUrl.getHost());
}
if (newUrl.getPort() != null)
{
request.setServerPort(newUrl.getPort());
}
}
else
{
// append redirect URL to current URL (what browser would do)
Url mergedURL = new Url(lastRequest.getUrl().getSegments(),
newUrl.getQueryParameters());
mergedURL.concatSegments(newUrl.getSegments());
request.setUrl(mergedURL);
}
processRequest(null, null, true);