From b80fec60ca1781b7adabb3a88157c741d9d53356 Mon Sep 17 00:00:00 2001 From: Daniel Grossmann-Kavanagh Date: Tue, 11 Jun 2019 21:09:45 +1000 Subject: [PATCH] Change normalize_path_middleware redirect from 301 -> 308 (#3579) --- CHANGES/3579.bugfix | 4 ++++ CONTRIBUTORS.txt | 1 + aiohttp/web_middlewares.py | 4 ++-- docs/web_reference.rst | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 CHANGES/3579.bugfix diff --git a/CHANGES/3579.bugfix b/CHANGES/3579.bugfix new file mode 100644 index 00000000000..57fa794343b --- /dev/null +++ b/CHANGES/3579.bugfix @@ -0,0 +1,4 @@ +Change normalize_path_middleware to use 308 redirect instead of 301. + +This behavior should prevent clients from being unable to use PUT/POST +methods on endpoints that are redirected because of a trailing slash. diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index f580fa78db4..45ef61829b6 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -61,6 +61,7 @@ Cong Xu Damien Nadé Dan Xu Daniel García +Daniel Grossmann-Kavanagh Daniel Nelson Danny Song David Bibb diff --git a/aiohttp/web_middlewares.py b/aiohttp/web_middlewares.py index fff5b8ad7b4..4f65ecbb7d0 100644 --- a/aiohttp/web_middlewares.py +++ b/aiohttp/web_middlewares.py @@ -2,7 +2,7 @@ import warnings from typing import TYPE_CHECKING, Awaitable, Callable, Tuple, Type, TypeVar -from .web_exceptions import HTTPMove, HTTPMovedPermanently +from .web_exceptions import HTTPMove, HTTPPermanentRedirect from .web_request import Request from .web_response import StreamResponse from .web_urldispatcher import SystemRoute @@ -45,7 +45,7 @@ def middleware(f: _Func) -> _Func: def normalize_path_middleware( *, append_slash: bool=True, remove_slash: bool=False, merge_slashes: bool=True, - redirect_class: Type[HTTPMove]=HTTPMovedPermanently) -> _Middleware: + redirect_class: Type[HTTPMove]=HTTPPermanentRedirect) -> _Middleware: """ Middleware factory which produces a middleware that normalizes the path of a request. By normalizing it means: diff --git a/docs/web_reference.rst b/docs/web_reference.rst index 19fc269fa4d..63edec261c7 100644 --- a/docs/web_reference.rst +++ b/docs/web_reference.rst @@ -2826,7 +2826,7 @@ Normalize path middleware append_slash=True, \ remove_slash=False, \ merge_slashes=True, \ - redirect_class=HTTPMovedPermanently) + redirect_class=HTTPPermanentRedirect) Middleware factory which produces a middleware that normalizes the path of a request. By normalizing it means: