don't intercept 307/308 routing redirects

These don't change the request body, so the debug error is no longer relevant.
This commit is contained in:
David Lord 2022-03-23 08:25:22 -07:00
parent cb7cd1e79b
commit c9a1f7ad65
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
3 changed files with 45 additions and 36 deletions

View file

@ -1457,17 +1457,26 @@ class Flask(Scaffold):
)
def raise_routing_exception(self, request: Request) -> "te.NoReturn":
"""Exceptions that are recording during routing are reraised with
this method. During debug we are not reraising redirect requests
for non ``GET``, ``HEAD``, or ``OPTIONS`` requests and we're raising
a different error instead to help debug situations.
"""Intercept routing exceptions and possibly do something else.
In debug mode, intercept a routing redirect and replace it with
an error if the body will be discarded.
With modern Werkzeug this shouldn't occur, since it now uses a
308 status which tells the browser to resend the method and
body.
.. versionchanged:: 2.1
Don't intercept 307 and 308 redirects.
:meta private:
:internal:
"""
if (
not self.debug
or not isinstance(request.routing_exception, RequestRedirect)
or request.method in ("GET", "HEAD", "OPTIONS")
or request.routing_exception.code in {307, 308}
or request.method in {"GET", "HEAD", "OPTIONS"}
):
raise request.routing_exception # type: ignore