Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 3b69635

Browse files
author
Paulo Janotti
authored
Make redirect test case really 'redirect' (#26674)
The test case was redirecting to the same URL this was bringing instability with the handlers (more with the managed). This change should make the test more reliable, as such moving it to inner loop. Fixes #23769 Since no action is planned for #26434 this also closes #26434
1 parent 179cf08 commit 3b69635

File tree

1 file changed

+33
-24
lines changed

1 file changed

+33
-24
lines changed

src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -568,13 +568,17 @@ public async Task GetAsync_AllowAutoRedirectFalse_RedirectFromHttpToHttp_StatusC
568568
}
569569
}
570570

571-
[ActiveIssue(23769)]
572-
[ActiveIssue(22707, TestPlatforms.AnyUnix)]
573-
[OuterLoop] // TODO: Issue #11345
574571
[Theory, MemberData(nameof(RedirectStatusCodesOldMethodsNewMethods))]
575572
public async Task AllowAutoRedirect_True_ValidateNewMethodUsedOnRedirection(
576573
int statusCode, string oldMethod, string newMethod)
577574
{
575+
if (!PlatformDetection.IsWindows && !UseManagedHandler && statusCode == 300 && oldMethod == "POST")
576+
{
577+
// Known behavior: curl does not change method to "GET"
578+
// https://github.com/dotnet/corefx/issues/26434
579+
newMethod = "POST";
580+
}
581+
578582
HttpClientHandler handler = CreateHttpClientHandler();
579583
using (var client = new HttpClient(handler))
580584
{
@@ -584,29 +588,34 @@ await LoopbackServer.CreateServerAsync(async (origServer, origUrl) =>
584588

585589
Task<HttpResponseMessage> getResponseTask = client.SendAsync(request);
586590

587-
Task<List<string>> serverTask = LoopbackServer.ReadRequestAndSendResponseAsync(origServer,
588-
$"HTTP/1.1 {statusCode} OK\r\n" +
589-
$"Date: {DateTimeOffset.UtcNow:R}\r\n" +
590-
$"Location: {origUrl}\r\n" +
591-
"\r\n");
592-
await Task.WhenAny(getResponseTask, serverTask);
593-
Assert.False(getResponseTask.IsCompleted, $"{getResponseTask.Status}: {getResponseTask.Exception}");
594-
await serverTask;
595-
596-
serverTask = LoopbackServer.ReadRequestAndSendResponseAsync(origServer,
597-
$"HTTP/1.1 200 OK\r\n" +
598-
$"Date: {DateTimeOffset.UtcNow:R}\r\n" +
599-
"\r\n");
600-
await TestHelper.WhenAllCompletedOrAnyFailed(getResponseTask, serverTask);
591+
await LoopbackServer.CreateServerAsync(async (redirServer, redirUrl) =>
592+
{
593+
// Original URL will redirect to a different URL
594+
Task<List<string>> serverTask = LoopbackServer.ReadRequestAndSendResponseAsync(origServer,
595+
$"HTTP/1.1 {statusCode} OK\r\n" +
596+
$"Date: {DateTimeOffset.UtcNow:R}\r\n" +
597+
$"Location: {redirUrl}\r\n" +
598+
"\r\n");
599+
await Task.WhenAny(getResponseTask, serverTask);
600+
Assert.False(getResponseTask.IsCompleted, $"{getResponseTask.Status}: {getResponseTask.Exception}");
601+
await serverTask;
602+
603+
// Redirected URL answers with success
604+
serverTask = LoopbackServer.ReadRequestAndSendResponseAsync(redirServer,
605+
$"HTTP/1.1 200 OK\r\n" +
606+
$"Date: {DateTimeOffset.UtcNow:R}\r\n" +
607+
"\r\n");
608+
await TestHelper.WhenAllCompletedOrAnyFailed(getResponseTask, serverTask);
601609

602-
List<string> receivedRequest = await serverTask;
603-
string[] statusLineParts = receivedRequest[0].Split(' ');
610+
List<string> receivedRequest = await serverTask;
611+
string[] statusLineParts = receivedRequest[0].Split(' ');
604612

605-
using (HttpResponseMessage response = await getResponseTask)
606-
{
607-
Assert.Equal(200, (int)response.StatusCode);
608-
Assert.Equal(newMethod, statusLineParts[0]);
609-
}
613+
using (HttpResponseMessage response = await getResponseTask)
614+
{
615+
Assert.Equal(200, (int)response.StatusCode);
616+
Assert.Equal(newMethod, statusLineParts[0]);
617+
}
618+
});
610619
});
611620
}
612621
}

0 commit comments

Comments
 (0)