Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public static IEnumerable<object[]> RedirectStatusCodesOldMethodsNewMethods()
{
yield return new object[] { statusCode, "GET", "GET" };
yield return new object[] { statusCode, "POST", statusCode <= 303 ? "GET" : "POST" };
yield return new object[] { statusCode, "PUT", statusCode == 303 ? "GET" : "PUT" };
yield return new object[] { statusCode, "DELETE", statusCode == 303 ? "GET" : "DELETE" };
yield return new object[] { statusCode, "PATCH", statusCode == 303 ? "GET" : "PATCH" };
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, "HEAD", "HEAD" };
}
}
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.Head;
Copy link
Contributor

Choose a reason for hiding this comment

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

One more nit: I think this should return false when requestMethod == HttpMethod.Get.

It probably doesn't make much difference, but it seems better to treat this as not changing the method, as we do with GET in other cases like Moved. If nothing else, it will avoid an unnecessary and confusing trace call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay - done.

default:
return false;
}
Expand Down