Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,15 @@ public static IEnumerable<object[]> RedirectStatusCodesOldMethodsNewMethods()
foreach (int statusCode in new[] { 300, 301, 302, 303, 307, 308 })
{
yield return new object[] { statusCode, "GET", "GET" };
yield return new object[] { statusCode, "POST", statusCode <= 303 ? "GET" : "POST" };
yield return new object[] { statusCode, "HEAD", "HEAD" };

yield return new object[] { statusCode, "POST", statusCode <= 303 ? "GET" : "POST" };

yield return new object[] { statusCode, "DELETE", statusCode == 303 ? "GET" : "DELETE" };
yield return new object[] { statusCode, "OPTIONS", statusCode == 303 ? "GET" : "OPTIONS" };
Copy link
Contributor

Choose a reason for hiding this comment

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

The one thing I'd add here is a completely custom method, e.g. "MYCUSTOMMETHOD" or whatever, and validate it gets changed to GET on 303.

Copy link
Contributor Author

@TimothyByrd TimothyByrd Mar 9, 2021

Choose a reason for hiding this comment

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

Done - first i verified that an incorrect test of
yield return new object[] { statusCode, "MYCUSTOMMETHOD", "MYCUSTOMMETHOD" };
fails and then that the correct
yield return new object[] { statusCode, "MYCUSTOMMETHOD", statusCode == 303 ? "GET" : "MYCUSTOMMETHOD" };
passes
(I like breaking tests so I can tell I did something when I make them work)

yield return new object[] { statusCode, "PATCH", statusCode == 303 ? "GET" : "PATCH" };
yield return new object[] { statusCode, "PUT", statusCode == 303 ? "GET" : "PUT" };
yield return new object[] { statusCode, "MYCUSTOMMETHOD", statusCode == 303 ? "GET" : "MYCUSTOMMETHOD" };
}
}
public HttpClientHandlerTest_AutoRedirect(ITestOutputHelper output) : base(output) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,10 @@ private static bool RequestRequiresForceGet(HttpStatusCode statusCode, HttpMetho
{
case HttpStatusCode.Moved:
case HttpStatusCode.Found:
case HttpStatusCode.SeeOther:
case HttpStatusCode.MultipleChoices:
return requestMethod == HttpMethod.Post;
case HttpStatusCode.SeeOther:
return requestMethod != HttpMethod.Get && requestMethod != HttpMethod.Head;
default:
return false;
}
Expand Down