From 9016ca3fd09afa85113366cfae9a3676db635598 Mon Sep 17 00:00:00 2001 From: agape1225 <49804691+agape1225@users.noreply.github.com> Date: Sat, 26 Jul 2025 22:47:21 +0900 Subject: [PATCH] fix(app): respect autocorrect_location_header in make_response --- CHANGES.rst | 7 +++++++ src/flask/app.py | 14 +++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) 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