Skip to content

Commit

Permalink
Fix #3207: Accept CIMultiDictProxy instances for headers argument in …
Browse files Browse the repository at this point in the history
…web.Response constructor
  • Loading branch information
asvetlov committed Oct 17, 2018
1 parent 8e991e6 commit 59183f0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES/3207.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Accept ``CIMultiDictProxy`` instances for ``headers`` argument in ``web.Response``
constructor.
2 changes: 1 addition & 1 deletion aiohttp/web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def __init__(self, *,

if headers is None:
headers = CIMultiDict()
elif not isinstance(headers, (CIMultiDict, CIMultiDictProxy)):
elif not isinstance(headers, CIMultiDict):
headers = CIMultiDict(headers)
else:
headers = cast(CIMultiDict, headers)
Expand Down
9 changes: 8 additions & 1 deletion tests/test_web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from unittest import mock

import pytest
from multidict import CIMultiDict
from multidict import CIMultiDict, CIMultiDictProxy

from aiohttp import HttpVersion, HttpVersion10, HttpVersion11, hdrs, signals
from aiohttp.payload import BytesPayload
Expand Down Expand Up @@ -1105,6 +1105,13 @@ def test_response_with_content_length_header_without_body() -> None:
assert resp.content_length == 123


def test_response_with_immutable_headers() -> None:
resp = Response(text='text',
headers=CIMultiDictProxy(CIMultiDict({'Header': 'Value'})))
assert resp.headers == {'Header': 'Value',
'Content-Type': 'text/plain; charset=utf-8'}


class TestJSONResponse:

def test_content_type_is_application_json_by_default(self) -> None:
Expand Down

0 comments on commit 59183f0

Please sign in to comment.