Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix redirect policy to check header name for valid Redirect requests #24570

Merged
merged 2 commits into from
Oct 6, 2021

Conversation

samvaity
Copy link
Member

@samvaity samvaity commented Oct 6, 2021

Fix redirect policy to extract redirect header name only for Redirect requests.

@ghost ghost added the Azure.Core azure-core label Oct 6, 2021
@samvaity samvaity changed the title Fix redirect policy to check redirect header name for Redirect requests Fix redirect policy to check header name for valid Redirect requests Oct 6, 2021
&& redirectUrl != null
&& !alreadyAttemptedRedirectUrl(redirectUrl, attemptedRedirectUrls)
&& isValidRedirectStatusCode(httpResponse.getStatusCode())
if (isValidRedirectStatusCode(httpResponse.getStatusCode())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To reduce nesting, you can check for (!isValidRedirectCount || !isAllowedRedirectMethod) then return false. That will allow you to remove the nested if statement.

Not Blocking

String redirectUrl = tryGetRedirectHeader(httpResponse.getHeaders(), getLocationHeader());
if (redirectUrl != null && !alreadyAttemptedRedirectUrl(redirectUrl, attemptedRedirectUrls)) {
logger.verbose("[Redirecting] Try count: {}, Attempted Redirect URLs: {}", tryCount,
attemptedRedirectUrls.toString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Given that we aren't guaranteed to be able to log at INFO we should use the ClientLogger.log(LogLevel, Supplier<String>) log method that will defer the toString call here.

@samvaity samvaity merged commit c1c4463 into Azure:main Oct 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure.Core azure-core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants