Response doesn't deal well with CIMultiDictProxy headers #3207
Closed
Description
Long story short
Example badness:
from aiohttp.web_exceptions import HTTPNotFound
from multidict import CIMultiDictProxy, CIMultiDict
raise HTTPNotFound(text='hi',headers=CIMultiDictProxy(CIMultiDict()))
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-12-51ed331c9efe> in <module>()
1 from aiohttp.web_exceptions import HTTPNotFound
2 from multidict import CIMultiDictProxy, CIMultiDict
----> 3 raise HTTPNotFound(text='hi',headers=CIMultiDictProxy(CIMultiDict()))
/usr/local/lib/python3.7/dist-packages/aiohttp/web_exceptions.py in __init__(self, headers, reason, body, text, content_type)
79 Response.__init__(self, status=self.status_code,
80 headers=headers, reason=reason,
---> 81 body=body, text=text, content_type=content_type)
82 Exception.__init__(self, self.reason)
83 if self.body is None and not self.empty_body:
/usr/local/lib/python3.7/dist-packages/aiohttp/web_response.py in __init__(self, body, status, reason, text, headers, content_type, charset)
467 charset = 'utf-8'
468 headers[hdrs.CONTENT_TYPE] = (
--> 469 content_type + '; charset=' + charset)
470 body = text.encode(charset)
471 text = None
TypeError: 'CIMultiDictProxy' object does not support item assignment
This is useful e.g. when an aiohttp app is acting like a proxy and is relaying errors from backends.
Expected behaviour
same as when using CIMultiDict:
from aiohttp.web_exceptions import HTTPNotFound
from multidict import CIMultiDictProxy, CIMultiDict
raise HTTPNotFound(text='hi',headers=CIMultiDict(CIMultiDict()))
---------------------------------------------------------------------------
HTTPNotFound Traceback (most recent call last)
<ipython-input-14-cc0e33a6117b> in <module>()
1 from aiohttp.web_exceptions import HTTPNotFound
2 from multidict import CIMultiDictProxy, CIMultiDict
----> 3 raise HTTPNotFound(text='hi',headers=CIMultiDict(CIMultiDict()))
HTTPNotFound: Not Found
Actual behaviour
see above
Steps to reproduce
Your environment
AIOHTTP 3.3.2
python3.7