Skip to content

Multiple headers with the same name gets replaced in test client #1655

@LukeMarlin

Description

@LukeMarlin

werkzeug.Headers allows to add multiple headers with the same name:

from werkzeug import Headers
h = Headers()
h.add("example", "value1")
h.add("example", "value2")
h.get_all("example")
> ['value1', 'value2']

Trying to write a test case to gracefully prevent users from doing so with a custom header, I noticed that when using werkzeug's TestClient and issuing a get, the request.headers context only receive the latest value, not both.

It seems that this is due to

for key, value in headers.to_wsgi_list():
result["HTTP_%s" % key.upper().replace("-", "_")] = value

Should these be modified to preserve all values instead of replacing them?
I'd gladly change it if it makes sense.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions