public class HttpRedirector extends Object
Request.followRedirects(boolean)
and then rely on this class to perform the redirect in a simpler way, for example:
HttpRedirector redirector = new HttpRedirector(httpClient);
Request request = httpClient.newRequest("http://host/path").followRedirects(false);
ContentResponse response = request.send();
while (redirector.isRedirect(response))
{
// Validate the redirect URI
if (!validate(redirector.extractRedirectURI(response)))
break;
Result result = redirector.redirect(request, response);
request = result.getRequest();
response = result.getResponse();
}
| Constructor and Description |
|---|
HttpRedirector(HttpClient client) |
| Modifier and Type | Method and Description |
|---|---|
URI |
extractRedirectURI(Response response)
Extracts and sanitizes (by making it absolute and escaping paths and query parameters)
the redirect URI of the given
response. |
protected void |
fail(Request request,
Response response,
Throwable failure) |
boolean |
isRedirect(Response response) |
Result |
redirect(Request request,
Response response)
Redirects the given
response, blocking until the redirect is complete. |
Request |
redirect(Request request,
Response response,
Response.CompleteListener listener)
Redirects the given
response asynchronously. |
public HttpRedirector(HttpClient client)
public boolean isRedirect(Response response)
response - the response to check for redirectspublic Result redirect(Request request, Response response) throws InterruptedException, ExecutionException
response, blocking until the redirect is complete.request - the original request that triggered the redirectresponse - the response to the original requestResult object containing the request to the redirected location and its responseInterruptedException - if the thread is interrupted while waiting for the redirect to completeExecutionException - if the redirect failedredirect(Request, Response, Response.CompleteListener)public Request redirect(Request request, Response response, Response.CompleteListener listener)
response asynchronously.request - the original request that triggered the redirectresponse - the response to the original requestlistener - the listener that receives response eventspublic URI extractRedirectURI(Response response)
response.response - the response to extract the redirect URI fromCopyright © 1995-2015 Webtide. All Rights Reserved.