Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Change normalize_path_middleware redirect from 301 -> 308 #3579

Merged
merged 1 commit into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -58,6 +58,7 @@ Colin Dunklau
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 HTTPMove, HTTPMovedPermanently
from .web_exceptions import HTTPMove, HTTPPermanentRedirect
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 @@ -2828,7 +2828,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