diff --git a/CHANGES/6594.feature b/CHANGES/6594.feature new file mode 100644 index 00000000000..4edadb07b3a --- /dev/null +++ b/CHANGES/6594.feature @@ -0,0 +1,2 @@ +Exported ``HTTPMove`` which can be used to catch any redirection request +that has a location -- :user:`dreamsorcerer`. diff --git a/aiohttp/web.py b/aiohttp/web.py index 4db66cda8bd..7be9d345226 100644 --- a/aiohttp/web.py +++ b/aiohttp/web.py @@ -44,6 +44,7 @@ HTTPLengthRequired as HTTPLengthRequired, HTTPMethodNotAllowed as HTTPMethodNotAllowed, HTTPMisdirectedRequest as HTTPMisdirectedRequest, + HTTPMove as HTTPMove, HTTPMovedPermanently as HTTPMovedPermanently, HTTPMultipleChoices as HTTPMultipleChoices, HTTPNetworkAuthenticationRequired as HTTPNetworkAuthenticationRequired, @@ -177,6 +178,7 @@ "HTTPLengthRequired", "HTTPMethodNotAllowed", "HTTPMisdirectedRequest", + "HTTPMove", "HTTPMovedPermanently", "HTTPMultipleChoices", "HTTPNetworkAuthenticationRequired", diff --git a/aiohttp/web_exceptions.py b/aiohttp/web_exceptions.py index ae706a18062..4c0a10aa75a 100644 --- a/aiohttp/web_exceptions.py +++ b/aiohttp/web_exceptions.py @@ -18,6 +18,7 @@ "HTTPNoContent", "HTTPResetContent", "HTTPPartialContent", + "HTTPMove", "HTTPMultipleChoices", "HTTPMovedPermanently", "HTTPFound", @@ -160,7 +161,7 @@ class HTTPPartialContent(HTTPSuccessful): ############################################################ -class _HTTPMove(HTTPRedirection): +class HTTPMove(HTTPRedirection): def __init__( self, location: StrOrURL, @@ -184,21 +185,21 @@ def __init__( self.location = location -class HTTPMultipleChoices(_HTTPMove): +class HTTPMultipleChoices(HTTPMove): status_code = 300 -class HTTPMovedPermanently(_HTTPMove): +class HTTPMovedPermanently(HTTPMove): status_code = 301 -class HTTPFound(_HTTPMove): +class HTTPFound(HTTPMove): status_code = 302 # This one is safe after a POST (the redirected location will be # retrieved with GET): -class HTTPSeeOther(_HTTPMove): +class HTTPSeeOther(HTTPMove): status_code = 303 @@ -208,16 +209,16 @@ class HTTPNotModified(HTTPRedirection): empty_body = True -class HTTPUseProxy(_HTTPMove): +class HTTPUseProxy(HTTPMove): # Not a move, but looks a little like one status_code = 305 -class HTTPTemporaryRedirect(_HTTPMove): +class HTTPTemporaryRedirect(HTTPMove): status_code = 307 -class HTTPPermanentRedirect(_HTTPMove): +class HTTPPermanentRedirect(HTTPMove): status_code = 308