You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
wsgiref.headers.Headers.__setitem__ deletes the old header before validating the new value #158225
In Lib/wsgiref/headers.py, Headers.setitem deletes the existing
header before validating the new name and value:
def __setitem__(self, name, val):
"""Set the value of a header."""
del self[name]
self._headers.append(
(self._convert_string_type(name, name=True),
self._convert_string_type(val, name=False)))
If _convert_string_type raises (for example when val is not a string),
the old header has already been removed and the new one is never added,
so the header disappears entirely.
Activity
pythongh-158225: Fix wsgiref Headers __setitem__ validation order
pythongh-158225: Fix wsgiref Headers __setitem__ validation order
pythongh-158225: Fix wsgiref Headers __setitem__ validation order
encukou commentedon Sep 29, 2026
This behaves as documented:
I guess it can be changed for the better, but, does this have any real-world impact?
Tony123-tech commentedon Oct 4, 2026
I opened a PR (#158226) but don't have a real-world case for the impact, so I closed it. Leaving the issue open in case someone hits it.