org.apache.http.impl.client

## Class DefaultRedirectStrategy

- java.lang.Object
- - org.apache.http.impl.client.DefaultRedirectStrategy

- All Implemented Interfaces:
    RedirectStrategy
  Direct Known Subclasses:
    LaxRedirectStrategy

      @Contract(threading=IMMUTABLE)
      public class DefaultRedirectStrategy
      extends Object
      implements RedirectStrategy

  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

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static DefaultRedirectStrategy` | `INSTANCE`
    `static String` | `REDIRECT_LOCATIONS` Deprecated. (4.3) use `HttpClientContext.REDIRECT_LOCATIONS`.
    `static int` | `SC_PERMANENT_REDIRECT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultRedirectStrategy()`
    `DefaultRedirectStrategy(String[] redirectMethods)` Constructs a new instance to redirect the given HTTP methods.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected URI` | `createLocationURI(String location)`
    `URI` | `getLocationURI(org.apache.http.HttpRequest request, org.apache.http.HttpResponse response, org.apache.http.protocol.HttpContext context)`
    `HttpUriRequest` | `getRedirect(org.apache.http.HttpRequest request, org.apache.http.HttpResponse response, org.apache.http.protocol.HttpContext context)` 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(String method)`
    `boolean` | `isRedirected(org.apache.http.HttpRequest request, org.apache.http.HttpResponse response, org.apache.http.protocol.HttpContext context)` Determines if a request should be redirected to a new location given the response from the target server.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### SC_PERMANENT_REDIRECT

          public static final int SC_PERMANENT_REDIRECT

      See Also:
        Constant Field Values

    - #### REDIRECT_LOCATIONS

          @Deprecated
          public static final String REDIRECT_LOCATIONS

      Deprecated. (4.3) use `HttpClientContext.REDIRECT_LOCATIONS`.
      See Also:
        Constant Field Values

    - #### INSTANCE

          public static final DefaultRedirectStrategy INSTANCE

  - ### Constructor Detail

    - #### DefaultRedirectStrategy

          public DefaultRedirectStrategy()

    - #### DefaultRedirectStrategy

          public DefaultRedirectStrategy(String[] redirectMethods)

      Constructs a new instance to redirect the given HTTP methods.
      Parameters:
        `redirectMethods` - The methods to redirect.
      Since:
        4.5.10

  - ### Method Detail

    - #### isRedirected

          public boolean isRedirected(org.apache.http.HttpRequest request,
                             org.apache.http.HttpResponse response,
                             org.apache.http.protocol.HttpContext context)
                               throws org.apache.http.ProtocolException

      Description copied from interface: `RedirectStrategy`
      Determines if a request should be redirected to a new location given the response from the target server.
      Specified by:
        `isRedirected` in interface `RedirectStrategy`
      Parameters:
        `request` - the executed request
        `response` - the response received from the target server
        `context` - the context for the request execution
      Returns:
        `true` if the request should be redirected, `false` otherwise
      Throws:
        `org.apache.http.ProtocolException`

    - #### getLocationURI

          public URI getLocationURI(org.apache.http.HttpRequest request,
                           org.apache.http.HttpResponse response,
                           org.apache.http.protocol.HttpContext context)
                             throws org.apache.http.ProtocolException

      Throws:
        `org.apache.http.ProtocolException`

    - #### createLocationURI

          protected URI createLocationURI(String location)
                                   throws org.apache.http.ProtocolException

      Throws:
        `org.apache.http.ProtocolException`
      Since:
        4.1

    - #### isRedirectable

          protected boolean isRedirectable(String method)

      Since:
        4.2

    - #### getRedirect

          public HttpUriRequest getRedirect(org.apache.http.HttpRequest request,
                                   org.apache.http.HttpResponse response,
                                   org.apache.http.protocol.HttpContext context)
                                     throws org.apache.http.ProtocolException

      Description copied from interface: `RedirectStrategy`
      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.
      Specified by:
        `getRedirect` in interface `RedirectStrategy`
      Parameters:
        `request` - the executed request
        `response` - the response received from the target server
        `context` - the context for the request execution
      Returns:
        redirected request
      Throws:
        `org.apache.http.ProtocolException`

Copyright © 1999–2022 The Apache Software Foundation. All rights reserved.