Merge pull request #3684 from MLH-Fellowship/3628-duplicate-headers

make_response uses headers.update
This commit is contained in:
David Lord 2020-07-23 16:57:19 -07:00 committed by GitHub
commit 2fa8eb3cfe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 7 deletions

View file

@ -27,9 +27,14 @@ Unreleased
instead of PyOpenSSL. :pr:`3492` instead of PyOpenSSL. :pr:`3492`
- When specifying a factory function with ``FLASK_APP``, keyword - When specifying a factory function with ``FLASK_APP``, keyword
argument can be passed. :issue:`3553` argument can be passed. :issue:`3553`
- When loading a ``.env`` or ``.flaskenv`` file on top level directory, - When loading a ``.env`` or ``.flaskenv`` file, the current working
Flask will not change current work directory to the location of dotenv directory is no longer changed to the location of the file.
files, in order to prevent potential confusion. :pr:`3560` :pr:`3560`
- When returning a ``(response, headers)`` tuple from a view, the
headers replace rather than extend existing headers on the response.
For example, this allows setting the ``Content-Type`` for
``jsonify()``. Use ``response.headers.extend()`` if extending is
desired. :issue:`3628`
Version 1.1.x Version 1.1.x

View file

@ -2045,7 +2045,7 @@ class Flask(_PackageBoundObject):
# extend existing headers with provided headers # extend existing headers with provided headers
if headers: if headers:
rv.headers.extend(headers) rv.headers.update(headers)
return rv return rv

View file

@ -1117,8 +1117,10 @@ def test_response_types(app, client):
@app.route("/response_headers") @app.route("/response_headers")
def from_response_headers(): def from_response_headers():
return ( return (
flask.Response("Hello world", 404, {"X-Foo": "Baz"}), flask.Response(
{"X-Foo": "Bar", "X-Bar": "Foo"}, "Hello world", 404, {"Content-Type": "text/html", "X-Foo": "Baz"}
),
{"Content-Type": "text/plain", "X-Foo": "Bar", "X-Bar": "Foo"},
) )
@app.route("/response_status") @app.route("/response_status")
@ -1155,7 +1157,8 @@ def test_response_types(app, client):
rv = client.get("/response_headers") rv = client.get("/response_headers")
assert rv.data == b"Hello world" assert rv.data == b"Hello world"
assert rv.headers.getlist("X-Foo") == ["Baz", "Bar"] assert rv.content_type == "text/plain"
assert rv.headers.getlist("X-Foo") == ["Bar"]
assert rv.headers["X-Bar"] == "Foo" assert rv.headers["X-Bar"] == "Foo"
assert rv.status_code == 404 assert rv.status_code == 404