Class LaxRedirectStrategy

java.lang.Object
org.apache.hc.client5.http.impl.DefaultRedirectStrategy
org.apache.hc.client5.http.impl.LaxRedirectStrategy
All Implemented Interfaces:
RedirectStrategy

@Contract(threading=STATELESS) public class LaxRedirectStrategy extends DefaultRedirectStrategy
A lax implementation of the RedirectStrategy that automatically handles HTTP redirects for HEAD, GET, POST, and DELETE requests based on the response status code.

This strategy relaxes the HTTP specification restrictions on automatic redirection of POST requests, allowing redirects for these methods where the specification might otherwise prohibit them. This can be useful in scenarios where a server indicates a redirect for a POST request that the client should follow.

This class is thread-safe and stateless, suitable for use across multiple threads without additional synchronization.

Since:
5.4
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final LaxRedirectStrategy
     
    private static final String[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
     
    boolean
    isRedirectAllowed(org.apache.hc.core5.http.HttpHost currentTarget, org.apache.hc.core5.http.HttpHost newTarget, org.apache.hc.core5.http.HttpRequest redirect, org.apache.hc.core5.http.protocol.HttpContext context)
    Determines if the given redirect should be executed or the redirect response should be returned to the caller without further processing.
    boolean
    isRedirected(org.apache.hc.core5.http.HttpRequest request, org.apache.hc.core5.http.HttpResponse response, org.apache.hc.core5.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 Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • INSTANCE

      public static final LaxRedirectStrategy INSTANCE
    • REDIRECT_METHODS

      private static final String[] REDIRECT_METHODS
  • Constructor Details

    • LaxRedirectStrategy

      public LaxRedirectStrategy()
  • Method Details

    • isRedirected

      public boolean isRedirected(org.apache.hc.core5.http.HttpRequest request, org.apache.hc.core5.http.HttpResponse response, org.apache.hc.core5.http.protocol.HttpContext context)
      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
      Overrides:
      isRedirected in class DefaultRedirectStrategy
      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
    • isRedirectAllowed

      public boolean isRedirectAllowed(org.apache.hc.core5.http.HttpHost currentTarget, org.apache.hc.core5.http.HttpHost newTarget, org.apache.hc.core5.http.HttpRequest redirect, org.apache.hc.core5.http.protocol.HttpContext context)
      Description copied from interface: RedirectStrategy
      Determines if the given redirect should be executed or the redirect response should be returned to the caller without further processing.

      It is legal for this method implementation to modify the redirect request in order to make it suitable for redirect execution.

      Specified by:
      isRedirectAllowed in interface RedirectStrategy
      Overrides:
      isRedirectAllowed in class DefaultRedirectStrategy
    • isRedirectable

      protected boolean isRedirectable(String method)