public final class DefaultRedirectStrategy extends Object implements RedirectStrategy
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 and Description |
---|
DefaultRedirectStrategy()
Creates an instance of
DefaultRedirectStrategy with a maximum number of redirect attempts 3,
header name "Location" to locate the redirect url in the response headers and HttpMethod.GET
and HttpMethod.HEAD as allowed methods for performing the redirect. |
DefaultRedirectStrategy(int maxAttempts)
Creates an instance of
DefaultRedirectStrategy with the provided number of redirect attempts and
default header name "Location" to locate the redirect url in the response headers and HttpMethod.GET
and HttpMethod.HEAD as allowed methods for performing the redirect. |
DefaultRedirectStrategy(int maxAttempts,
String locationHeader,
Set<HttpMethod> allowedMethods)
Creates an instance of
DefaultRedirectStrategy . |
Modifier and Type | Method and Description |
---|---|
HttpRequest |
createRedirectRequest(HttpResponse httpResponse)
Creates an
request for the redirect attempt. |
int |
getMaxAttempts()
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.
|
public DefaultRedirectStrategy()
DefaultRedirectStrategy
with a maximum number of redirect attempts 3,
header name "Location" to locate the redirect url in the response headers and HttpMethod.GET
and HttpMethod.HEAD
as allowed methods for performing the redirect.public DefaultRedirectStrategy(int maxAttempts)
DefaultRedirectStrategy
with the provided number of redirect attempts and
default header name "Location" to locate the redirect url in the response headers and HttpMethod.GET
and HttpMethod.HEAD
as allowed methods for performing the redirect.maxAttempts
- The max number of redirect attempts that can be made.IllegalArgumentException
- if maxAttempts
is less than 0.public DefaultRedirectStrategy(int maxAttempts, String locationHeader, Set<HttpMethod> allowedMethods)
DefaultRedirectStrategy
.maxAttempts
- The max number of redirect attempts that can be made.locationHeader
- The header name containing the redirect URL.allowedMethods
- The set of HttpMethod
that are allowed to be redirected.IllegalArgumentException
- if maxAttempts
is less than 0.public boolean shouldAttemptRedirect(HttpPipelineCallContext context, HttpResponse httpResponse, int tryCount, Set<String> attemptedRedirectUrls)
RedirectStrategy
shouldAttemptRedirect
in interface RedirectStrategy
context
- the HTTP pipeline context
.httpResponse
- the HttpRequest
containing the redirect url present in the response headerstryCount
- redirect attempts so farattemptedRedirectUrls
- attempted redirect locations used so far.true
if the request should be redirected, false
otherwisepublic HttpRequest createRedirectRequest(HttpResponse httpResponse)
RedirectStrategy
request
for the redirect attempt.createRedirectRequest
in interface RedirectStrategy
httpResponse
- the HttpResponse
containing the redirect url present in the response headersHttpRequest
to redirect the incoming request.public int getMaxAttempts()
RedirectStrategy
getMaxAttempts
in interface RedirectStrategy
Copyright © 2021 Microsoft Corporation. All rights reserved.