Applications can disable redirection via 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();
}
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| private static final String | |
| private final HttpClient | |
| private static final String | |
| private static final String | |
| private static final Logger | |
| private static final String | |
| private static final String | |
| private static final String | |
| private static final Pattern |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public URI | Returns: the absolute redirect URI, or null if the response does not contain a valid redirect locationthe response to extract the redirect URI from response)Extracts and sanitizes (by making it absolute and escaping paths and query parameters)
the redirect URI of the given |
| protected void | |
| protected void | |
| private void | |
| public boolean | Returns: whether the response code is an HTTP redirect codethe response to check for redirects response)
|
| public Result | |
| public Request | Returns: the request to the redirected locationthe original request that triggered the redirect request, Response the response to the original request response, Response.the listener that receives response events listenerRedirects the given |
| private Request | |
| private Request | |
| private URI | |
| private Request | sendRedirect(HttpRequest httpRequest, Response response, Response.
|
| ATTRIBUTE | back to summary |
|---|---|
| private static final String ATTRIBUTE | |
| AUTHORITY_REGEXP | back to summary |
|---|---|
| private static final String AUTHORITY_REGEXP | |
| client | back to summary |
|---|---|
| private final HttpClient client | |
| DESTINATION_REGEXP | back to summary |
|---|---|
| private static final String DESTINATION_REGEXP | |
| FRAGMENT_REGEXP | back to summary |
|---|---|
| private static final String FRAGMENT_REGEXP | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| PATH_REGEXP | back to summary |
|---|---|
| private static final String PATH_REGEXP | |
| QUERY_REGEXP | back to summary |
|---|---|
| private static final String QUERY_REGEXP | |
| SCHEME_REGEXP | back to summary |
|---|---|
| private static final String SCHEME_REGEXP | |
| URI_PATTERN | back to summary |
|---|---|
| private static final Pattern URI_PATTERN | |
| HttpRedirector | back to summary |
|---|---|
| public HttpRedirector(HttpClient client) | |
| extractRedirectURI | back to summary |
|---|---|
| public URI extractRedirectURI(Response response) Extracts and sanitizes (by making it absolute and escaping paths and query parameters)
the redirect URI of the given | |
| fail | back to summary |
|---|---|
| protected void fail(Request request, Response response, Throwable failure) | |
| fail | back to summary |
|---|---|
| protected void fail(Request request, Throwable failure, Response response) | |
| fail | back to summary |
|---|---|
| private void fail(Request request, Throwable requestFailure, Response response, Throwable responseFailure) | |
| isRedirect | back to summary |
|---|---|
public boolean isRedirect(Response response)
| |
| redirect | back to summary |
|---|---|
| public Result redirect(Request request, Response response) throws InterruptedException, ExecutionException Redirects the given
| |
| redirect | back to summary |
|---|---|
| public Request redirect(Request request, Response response, Response. Redirects the given
| |
| redirect | back to summary |
|---|---|
| private Request redirect(Request request, Response response, Response. | |
| redirect | back to summary |
|---|---|
| private Request redirect(Request request, Response response, Response. | |
| sanitize | back to summary |
|---|---|
| private URI sanitize(String location) | |
| sendRedirect | back to summary |
|---|---|
| private Request sendRedirect(HttpRequest httpRequest, Response response, Response. | |