File tree Expand file tree Collapse file tree 4 files changed +22
-9
lines changed
Expand file tree Collapse file tree 4 files changed +22
-9
lines changed Original file line number Diff line number Diff line change 3232from ..pipeline .transport ._requests_basic import StreamDownloadGenerator
3333
3434class _ItemsView (collections .ItemsView ):
35+
36+ def __init__ (self , ref ):
37+ self ._ref = ref
38+
3539 def __contains__ (self , item ):
3640 if not (isinstance (item , (list , tuple )) and len (item ) == 2 ):
3741 return False # requests raises here, we just return False
38- for k , v in self .__iter__ ():
42+ for k , v in self ._ref . __iter__ ():
3943 if item [0 ].lower () == k .lower () and item [1 ] == v :
4044 return True
4145 return False
@@ -51,7 +55,7 @@ class _CaseInsensitiveDict(CaseInsensitiveDict):
5155
5256 def items (self ):
5357 """Return a new view of the dictionary's items."""
54- return _ItemsView (self )
58+ return _ItemsView (super ( _CaseInsensitiveDict , self ). items () )
5559
5660
5761if TYPE_CHECKING :
Original file line number Diff line number Diff line change @@ -222,13 +222,11 @@ class _HttpResponseBase: # pylint: disable=too-many-instance-attributes
222222 def __init__ (
223223 self ,
224224 * ,
225- request : HttpRequest ,
226- ** kwargs
225+ request : HttpRequest
227226 ):
228227 self .request = request
229- self ._internal_response = kwargs .pop ("internal_response" )
230228 self .status_code = None
231- self .headers = {} # type: HeadersType
229+ self .headers = _case_insensitive_dict ({})
232230 self .reason = None
233231 self .is_closed = False
234232 self .is_stream_consumed = False
@@ -285,7 +283,7 @@ def json(self) -> Any:
285283 """
286284 # this will trigger errors if response is not read in
287285 self .content # pylint: disable=pointless-statement
288- if not self ._json :
286+ if self ._json is None :
289287 self ._json = loads (self .text ())
290288 return self ._json
291289
Original file line number Diff line number Diff line change 77import pytest
88import platform
99from azure .core .rest import HttpRequest
10+ import aiohttp
11+ from azure .core .rest ._aiohttp import RestAioHttpTransportResponse
1012
1113# flask returns these response headers, which we don't really need for these following tests
1214RESPONSE_HEADERS_TO_IGNORE = [
Original file line number Diff line number Diff line change 44# license information.
55# -------------------------------------------------------------------------
66import sys
7- from typing import ValuesView
7+ from requests import Response
88import pytest
9+ from azure .core .rest ._requests_basic import RestRequestsTransportResponse
910
1011# NOTE: These tests are heavily inspired from the httpx test suite: https://github.com/encode/httpx/tree/master/tests
1112# Thank you httpx for your wonderful tests!
@@ -247,4 +248,12 @@ def test_multiple_headers_duplicate_case_insensitive(get_response_headers):
247248
248249def test_multiple_headers_commas (get_response_headers ):
249250 h = get_response_headers (HttpRequest ("GET" , "/headers/duplicate/commas" ))
250- assert h ["Set-Cookie" ] == "a, b, c"
251+ assert h ["Set-Cookie" ] == "a, b, c"
252+
253+ def test_headers_link ():
254+ headers = {}
255+ internal_response = Response ()
256+ internal_response .headers = headers
257+ response = RestRequestsTransportResponse (request = None , internal_response = internal_response )
258+ headers ["Update" ] = "foo"
259+ assert response .headers ["Update" ] == "foo"
You can’t perform that action at this time.
0 commit comments