#13868·aiohttp

HeadersDictProxy treats mixed-case duplicate headers as distinct keys

Author: 00200200Created Sep 29, 2026Updated Oct 1, 2026

Describe the bug

HeadersDictProxy deduplicates mapping keys with a case-sensitive set. HTTP header names are case-insensitive, and CIMultiDict keeps each insertion's original casing, so X-Foo and x-foo both appear in list(headers) / len(headers) even though __getitem__ already joins them.

To Reproduce

python
from multidict import CIMultiDict
from aiohttp.helpers import HeadersDictProxy

md = CIMultiDict()
md.add("X-Foo", "1")
md.add("x-foo", "2")
md.add("Host", "a")
headers = HeadersDictProxy(md)

print(list(headers))  # ['X-Foo', 'x-foo', 'Host']
print(len(headers))   # 3
print(list(headers.items()))
# [('X-Foo', '1, 2'), ('x-foo', '1, 2'), ('Host', 'a')]

The same split keys show up on parsed request messages:

python
# GET / HTTP/1.1 + Host: a + X-Foo: 1 + x-foo: 2
# list(msg.headers) == ['Host', 'X-Foo', 'x-foo']
# len(msg.headers) == 3

Expected behavior

One mapping key per case-insensitive header name, keeping the first-seen casing:

python
list(headers) == ['X-Foo', 'Host']
len(headers) == 2
list(headers.items()) == [('X-Foo', '1, 2'), ('Host', 'a')]
headers["x-foo"] == "1, 2"

Related component

Both (request/response headers exposed via HeadersDictProxy)