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

Make 303 redirects do GET like Net Framework #49095

Merged
merged 10 commits into from
Mar 9, 2021
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