Fix max redirect count (#20428)

Without this change, RedirectHandler always follows MaxRedirects + 1. If MaxRedirects was initially set to 1, the body of the while statement is executed twice. This defect expresses itself when calling WebApplicationFactory<Startup>.CreateClient() with WebApplicationFactoryClientOptions.MaxAutomaticRedirections >= 1 and .AllowAutoRedirects = true in integration tests.
This commit is contained in:
Michiel van Wessem 2020-04-08 09:50:43 -07:00 committed by GitHub
parent f9ee790d02
commit ada3bdf45d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Mvc.Testing.Handlers
var originalRequestContent = HasBody(request) ? await DuplicateRequestContent(request) : null;
CopyRequestHeaders(request.Headers, redirectRequest.Headers);
var response = await base.SendAsync(request, cancellationToken);
while (IsRedirect(response) && remainingRedirects >= 0)
while (IsRedirect(response) && remainingRedirects > 0)
{
remainingRedirects--;
UpdateRedirectRequest(response, redirectRequest, originalRequestContent);
@ -168,4 +168,4 @@ namespace Microsoft.AspNetCore.Mvc.Testing.Handlers
response.StatusCode == HttpStatusCode.RedirectKeepVerb ||
(int)response.StatusCode == 308;
}
}
}