Package com.azure.core.http.policy
Class DefaultRedirectStrategy
java.lang.Object
com.azure.core.http.policy.DefaultRedirectStrategy
- All Implemented Interfaces:
RedirectStrategy
A default implementation of
RedirectStrategy
that 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
ConstructorDescriptionCreates an instance ofDefaultRedirectStrategy
with a maximum number of redirect attempts 3, header name "Location" to locate the redirect url in the response headers andHttpMethod.GET
andHttpMethod.HEAD
as allowed methods for performing the redirect.DefaultRedirectStrategy
(int maxAttempts) Creates an instance ofDefaultRedirectStrategy
with the provided number of redirect attempts and default header name "Location" to locate the redirect url in the response headers andHttpMethod.GET
andHttpMethod.HEAD
as allowed methods for performing the redirect.DefaultRedirectStrategy
(int maxAttempts, String locationHeader, Set<HttpMethod> allowedMethods) Creates an instance ofDefaultRedirectStrategy
. -
Method Summary
Modifier and TypeMethodDescriptioncreateRedirectRequest
(HttpResponse httpResponse) Creates anrequest
for the redirect attempt.int
Max number of redirect attempts to be made.boolean
shouldAttemptRedirect
(HttpPipelineCallContext context, HttpResponse httpResponse, int tryCount, Set<String> attemptedRedirectUrls) Determines if the url should be redirected between each try.
-
Constructor Details
-
DefaultRedirectStrategy
public DefaultRedirectStrategy()Creates an instance ofDefaultRedirectStrategy
with a maximum number of redirect attempts 3, header name "Location" to locate the redirect url in the response headers andHttpMethod.GET
andHttpMethod.HEAD
as allowed methods for performing the redirect. -
DefaultRedirectStrategy
public DefaultRedirectStrategy(int maxAttempts) Creates an instance ofDefaultRedirectStrategy
with the provided number of redirect attempts and default header name "Location" to locate the redirect url in the response headers andHttpMethod.GET
andHttpMethod.HEAD
as allowed methods for performing the redirect.- Parameters:
maxAttempts
- The max number of redirect attempts that can be made.- Throws:
IllegalArgumentException
- ifmaxAttempts
is 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 ofHttpMethod
that are allowed to be redirected.- Throws:
IllegalArgumentException
- ifmaxAttempts
is less than 0.
-
-
Method Details
-
shouldAttemptRedirect
public boolean shouldAttemptRedirect(HttpPipelineCallContext context, HttpResponse httpResponse, int tryCount, Set<String> attemptedRedirectUrls) Description copied from interface:RedirectStrategy
Determines if the url should be redirected between each try.- Specified by:
shouldAttemptRedirect
in interfaceRedirectStrategy
- Parameters:
context
- theHTTP pipeline context
.httpResponse
- theHttpRequest
containing the redirect url present in the response headerstryCount
- redirect attempts so farattemptedRedirectUrls
- attempted redirect locations used so far.- Returns:
true
if the request should be redirected,false
otherwise
-
createRedirectRequest
Description copied from interface:RedirectStrategy
Creates anrequest
for the redirect attempt.- Specified by:
createRedirectRequest
in interfaceRedirectStrategy
- Parameters:
httpResponse
- theHttpResponse
containing the redirect url present in the response headers- Returns:
- the modified
HttpRequest
to redirect the incoming request.
-
getMaxAttempts
public int getMaxAttempts()Description copied from interface:RedirectStrategy
Max number of redirect attempts to be made.- Specified by:
getMaxAttempts
in interfaceRedirectStrategy
- Returns:
- The max number of redirect attempts.
-