diff --git a/CHANGES.rst b/CHANGES.rst index d400ef3e..6073e6a3 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,10 @@ +Version 3.1.2 +------------- + +Unreleased + +- Respect ``autocorrect_location_header`` in ``make_response``. :issue:`5774` + Version 3.1.1 ------------- diff --git a/src/flask/app.py b/src/flask/app.py index 1232b03d..ca7e59f5 100644 --- a/src/flask/app.py +++ b/src/flask/app.py @@ -1262,8 +1262,20 @@ class Flask(App): else: rv.status_code = status - # extend existing headers with provided headers if headers: + headers = Headers(headers) + # Pop the Location header to handle it separately. + # This handles both "Location" and "location" keys. + location = headers.pop("Location", None) or headers.pop("location", None) + + # If a Location header was found, set it using the response + # .location property. This respects the 'autocorrect_location_header' + # flag, which is the purpose of this fix. + + if location is not None: + rv.location = location + + # Add the remaining headers to the response. rv.headers.update(headers) return rv