Skip to content

Commit

Permalink
[3.5] Change normalize_path_middleware redirect from 301 -> 308 (#3579)…
Browse files Browse the repository at this point in the history
…. (#3835)

(cherry picked from commit b80fec6)

Co-authored-by: Daniel Grossmann-Kavanagh <[email protected]>
  • Loading branch information
2 people authored and webknjaz committed Jun 11, 2019
1 parent 3e06f09 commit f6e5a5b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES/3579.bugfix
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Cong Xu
Damien Nadé
Dan Xu
Daniel García
Daniel Grossmann-Kavanagh
Daniel Nelson
Danny Song
David Bibb
Expand Down
4 changes: 2 additions & 2 deletions aiohttp/web_middlewares.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from typing import TYPE_CHECKING, Awaitable, Callable, Tuple, Type, TypeVar

from .web_exceptions import HTTPMovedPermanently, _HTTPMove
from .web_exceptions import HTTPPermanentRedirect, _HTTPMove
from .web_request import Request
from .web_response import StreamResponse
from .web_urldispatcher import SystemRoute
Expand Down Expand Up @@ -42,7 +42,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:
Expand Down
2 changes: 1 addition & 1 deletion docs/web_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2871,7 +2871,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:
Expand Down

0 comments on commit f6e5a5b

Please sign in to comment.