fix(app): respect autocorrect_location_header in make_response

This commit is contained in:
agape1225 2025-07-26 22:47:21 +09:00
parent e5fd6e11e4
commit 9016ca3fd0
2 changed files with 20 additions and 1 deletions

View file

@ -1,3 +1,10 @@
Version 3.1.2
-------------
Unreleased
- Respect ``autocorrect_location_header`` in ``make_response``. :issue:`5774`
Version 3.1.1
-------------

View file

@ -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