Top Description Fields Constructors Methods
org.apache.http.impl.client

public Class DefaultRedirectStrategy

extends Object
implements RedirectStrategy
Class Inheritance
All Implemented Interfaces
org.apache.http.client.RedirectStrategy
Known Direct Subclasses
org.apache.http.impl.client.LaxRedirectStrategy
Annotations
@Contract
threading:IMMUTABLE
Imports
java.net.URI, .URISyntaxException, java.util.Arrays, org.apache.commons.logging.Log, .LogFactory, org.apache.http.Header, .HttpHost, .HttpRequest, .HttpResponse, .HttpStatus, .ProtocolException, org.apache.http.annotation.Contract, .ThreadingBehavior, org.apache.http.client.CircularRedirectException, .RedirectStrategy, org.apache.http.client.config.RequestConfig, org.apache.http.client.methods.HttpGet, .HttpHead, .HttpUriRequest, .RequestBuilder, org.apache.http.client.protocol.HttpClientContext, org.apache.http.client.utils.URIUtils, org.apache.http.protocol.HttpContext, org.apache.http.util.Args, .Asserts

Default implementation of RedirectStrategy. This strategy honors the restrictions on automatic redirection of entity enclosing methods such as POST and PUT imposed by the HTTP specification. 302 Moved Temporarily, 301 Moved Permanently and 307 Temporary Redirect status codes will result in an automatic redirect of HEAD and GET methods only. POST and PUT methods will not be automatically redirected as requiring user confirmation.

The restriction on automatic redirection of POST methods can be relaxed by using LaxRedirectStrategy instead of DefaultRedirectStrategy.

Since
4.1
See Also
LaxRedirectStrategy

Field Summary

Modifier and TypeField and Description
public static final DefaultRedirectStrategy
private final Log
public static final String
private final String[]
public static final int

Constructor Summary

AccessConstructor and Description
public
public
DefaultRedirectStrategy(final String[]
The methods to redirect.
redirectMethods
)

Constructs a new instance to redirect the given HTTP methods.

Method Summary

Modifier and TypeMethod and Description
protected URI
createLocationURI(final String location)

public URI
getLocationURI(final HttpRequest request, final HttpResponse response, final HttpContext context)

public HttpUriRequest
getRedirect(final HttpRequest
the executed request
request
,
final HttpResponse
the response received from the target server
response
,
final HttpContext
the context for the request execution
context
)

Implements org.apache.http.client.RedirectStrategy.getRedirect.

Determines the redirect location given the response from the target server and the current request execution context and generates a new request to be sent to the location.
protected boolean
isRedirectable(final String method)

public boolean
isRedirected(final HttpRequest
the executed request
request
,
final HttpResponse
the response received from the target server
response
,
final HttpContext
the context for the request execution
context
)

Implements org.apache.http.client.RedirectStrategy.isRedirected.

Determines if a request should be redirected to a new location given the response from the target server.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
public static final DefaultRedirectStrategy INSTANCE
logback to summary
private final Log log
REDIRECT_LOCATIONSback to summary
public static final String REDIRECT_LOCATIONS
Annotations
@Deprecated
redirectMethodsback to summary
private final String[] redirectMethods
SC_PERMANENT_REDIRECTback to summary
public static final int SC_PERMANENT_REDIRECT

Constructor Detail

DefaultRedirectStrategyback to summary
public DefaultRedirectStrategy()
DefaultRedirectStrategyback to summary
public DefaultRedirectStrategy(final String[] redirectMethods)

Constructs a new instance to redirect the given HTTP methods.

Parameters
redirectMethods:String[]

The methods to redirect.

Since
4.5.10

Method Detail

createLocationURIback to summary
protected URI createLocationURI(final String location) throws ProtocolException
Since
4.1
getLocationURIback to summary
public URI getLocationURI(final HttpRequest request, final HttpResponse response, final HttpContext context) throws ProtocolException
getRedirectback to summary
public HttpUriRequest getRedirect(final HttpRequest request, final HttpResponse response, final HttpContext context) throws ProtocolException

Implements org.apache.http.client.RedirectStrategy.getRedirect.

Doc from org.apache.http.client.RedirectStrategy.getRedirect.

Determines the redirect location given the response from the target server and the current request execution context and generates a new request to be sent to the location.

Parameters
request:HttpRequest

the executed request

response:HttpResponse

the response received from the target server

context:HttpContext

the context for the request execution

Returns:HttpUriRequest

redirected request

Annotations
@Override
isRedirectableback to summary
protected boolean isRedirectable(final String method)
Since
4.2
isRedirectedback to summary
public boolean isRedirected(final HttpRequest request, final HttpResponse response, final HttpContext context) throws ProtocolException

Implements org.apache.http.client.RedirectStrategy.isRedirected.

Doc from org.apache.http.client.RedirectStrategy.isRedirected.

Determines if a request should be redirected to a new location given the response from the target server.

Parameters
request:HttpRequest

the executed request

response:HttpResponse

the response received from the target server

context:HttpContext

the context for the request execution

Returns:boolean

true if the request should be redirected, false otherwise

Annotations
@Override