Package com.azure.core.http.policy
Class DefaultRedirectStrategy
- java.lang.Object
-
- com.azure.core.http.policy.DefaultRedirectStrategy
-
- All Implemented Interfaces:
RedirectStrategy
public final class DefaultRedirectStrategy extends Object implements RedirectStrategy
A default implementation ofRedirectStrategythat uses the provided maximum retry attempts, header name to look up redirect url value for, http methods and a known set of redirect status response codes (301, 302, 307, 308) to determine if request should be redirected.
-
-
Constructor Summary
Constructors Constructor Description DefaultRedirectStrategy()Creates an instance ofDefaultRedirectStrategywith a maximum number of redirect attempts 3, header name "Location" to locate the redirect url in the response headers andHttpMethod.GETandHttpMethod.HEADas allowed methods for performing the redirect.DefaultRedirectStrategy(int maxAttempts)Creates an instance ofDefaultRedirectStrategywith the provided number of redirect attempts and default header name "Location" to locate the redirect url in the response headers andHttpMethod.GETandHttpMethod.HEADas allowed methods for performing the redirect.DefaultRedirectStrategy(int maxAttempts, String locationHeader, Set<HttpMethod> allowedMethods)Creates an instance ofDefaultRedirectStrategy.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpRequestcreateRedirectRequest(HttpResponse httpResponse)Creates anrequestfor the redirect attempt.intgetMaxAttempts()Max number of redirect attempts to be made.booleanshouldAttemptRedirect(HttpPipelineCallContext context, HttpResponse httpResponse, int tryCount, Set<String> attemptedRedirectUrls)Determines if the url should be redirected between each try.
-
-
-
Constructor Detail
-
DefaultRedirectStrategy
public DefaultRedirectStrategy()
Creates an instance ofDefaultRedirectStrategywith a maximum number of redirect attempts 3, header name "Location" to locate the redirect url in the response headers andHttpMethod.GETandHttpMethod.HEADas allowed methods for performing the redirect.
-
DefaultRedirectStrategy
public DefaultRedirectStrategy(int maxAttempts)
Creates an instance ofDefaultRedirectStrategywith the provided number of redirect attempts and default header name "Location" to locate the redirect url in the response headers andHttpMethod.GETandHttpMethod.HEADas allowed methods for performing the redirect.- Parameters:
maxAttempts- The max number of redirect attempts that can be made.- Throws:
IllegalArgumentException- ifmaxAttemptsis less than 0.
-
DefaultRedirectStrategy
public DefaultRedirectStrategy(int maxAttempts, String locationHeader, Set<HttpMethod> allowedMethods)Creates an instance ofDefaultRedirectStrategy.- Parameters:
maxAttempts- The max number of redirect attempts that can be made.locationHeader- The header name containing the redirect URL.allowedMethods- The set ofHttpMethodthat are allowed to be redirected.- Throws:
IllegalArgumentException- ifmaxAttemptsis less than 0.
-
-
Method Detail
-
shouldAttemptRedirect
public boolean shouldAttemptRedirect(HttpPipelineCallContext context, HttpResponse httpResponse, int tryCount, Set<String> attemptedRedirectUrls)
Description copied from interface:RedirectStrategyDetermines if the url should be redirected between each try.- Specified by:
shouldAttemptRedirectin interfaceRedirectStrategy- Parameters:
context- theHTTP pipeline context.httpResponse- theHttpRequestcontaining the redirect url present in the response headerstryCount- redirect attempts so farattemptedRedirectUrls- attempted redirect locations used so far.- Returns:
trueif the request should be redirected,falseotherwise
-
createRedirectRequest
public HttpRequest createRedirectRequest(HttpResponse httpResponse)
Description copied from interface:RedirectStrategyCreates anrequestfor the redirect attempt.- Specified by:
createRedirectRequestin interfaceRedirectStrategy- Parameters:
httpResponse- theHttpResponsecontaining the redirect url present in the response headers- Returns:
- the modified
HttpRequestto redirect the incoming request.
-
getMaxAttempts
public int getMaxAttempts()
Description copied from interface:RedirectStrategyMax number of redirect attempts to be made.- Specified by:
getMaxAttemptsin interfaceRedirectStrategy- Returns:
- The max number of redirect attempts.
-
-