Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism committed Nov 1, 2024
2 parents 1e775e3 + 07af92d commit 357681f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ Unreleased
Version 3.1.1
-------------

Unreleased
Released 2024-11-01

- Fix an issue that caused ``str(Request.headers)`` to always appear empty.
:issue:`2985`


Version 3.1.0
Expand Down
4 changes: 2 additions & 2 deletions src/werkzeug/datastructures/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,13 +568,13 @@ def __copy__(self) -> te.Self:
def __str__(self) -> str:
"""Returns formatted headers suitable for HTTP transmission."""
strs = []
for key, value in self._list:
for key, value in self.to_wsgi_list():
strs.append(f"{key}: {value}")
strs.append("\r\n")
return "\r\n".join(strs)

def __repr__(self) -> str:
return f"{type(self).__name__}({self._list!r})"
return f"{type(self).__name__}({list(self)!r})"


def _options_header_vkw(value: str, kw: dict[str, t.Any]) -> str:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_datastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,10 @@ def test_ior(self) -> None:
with pytest.raises(TypeError):
headers |= {"y": "2"}

def test_str(self) -> None:
headers = ds.EnvironHeaders({"CONTENT_LENGTH": "50", "HTTP_HOST": "test"})
assert str(headers) == "Content-Length: 50\r\nHost: test\r\n\r\n"


class TestHeaderSet:
storage_class = ds.HeaderSet
Expand Down

0 comments on commit 357681f

Please sign in to comment.