mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-10 17:45:35 +00:00
aiohttp: Add support for multiple headers with same key
This commit is contained in:
committed by
Kevin McCarthy
parent
2f53776ffb
commit
69e4316545
@@ -59,14 +59,14 @@ def build_response(vcr_request, vcr_response, history):
|
|||||||
request_info = RequestInfo(
|
request_info = RequestInfo(
|
||||||
url=URL(vcr_request.url),
|
url=URL(vcr_request.url),
|
||||||
method=vcr_request.method,
|
method=vcr_request.method,
|
||||||
headers=CIMultiDictProxy(CIMultiDict(vcr_request.headers)),
|
headers=_deserialize_headers(vcr_request.headers),
|
||||||
real_url=URL(vcr_request.url),
|
real_url=URL(vcr_request.url),
|
||||||
)
|
)
|
||||||
response = MockClientResponse(vcr_request.method, URL(vcr_response.get("url")), request_info=request_info)
|
response = MockClientResponse(vcr_request.method, URL(vcr_response.get("url")), request_info=request_info)
|
||||||
response.status = vcr_response["status"]["code"]
|
response.status = vcr_response["status"]["code"]
|
||||||
response._body = vcr_response["body"].get("string", b"")
|
response._body = vcr_response["body"].get("string", b"")
|
||||||
response.reason = vcr_response["status"]["message"]
|
response.reason = vcr_response["status"]["message"]
|
||||||
response._headers = CIMultiDictProxy(CIMultiDict(vcr_response["headers"]))
|
response._headers = _deserialize_headers(vcr_response["headers"])
|
||||||
response._history = tuple(history)
|
response._history = tuple(history)
|
||||||
|
|
||||||
response.close()
|
response.close()
|
||||||
@@ -81,7 +81,23 @@ def _serialize_headers(headers):
|
|||||||
"""
|
"""
|
||||||
# Mark strings as keys so 'istr' types don't show up in
|
# Mark strings as keys so 'istr' types don't show up in
|
||||||
# the cassettes as comments.
|
# the cassettes as comments.
|
||||||
return {str(k): v for k, v in headers.items()}
|
serialized_headers = {}
|
||||||
|
for k, v in headers.items():
|
||||||
|
serialized_headers.setdefault(str(k), []).append(v)
|
||||||
|
|
||||||
|
return serialized_headers
|
||||||
|
|
||||||
|
|
||||||
|
def _deserialize_headers(headers):
|
||||||
|
deserialized_headers = CIMultiDict()
|
||||||
|
for k, vs in headers.items():
|
||||||
|
if isinstance(vs, list):
|
||||||
|
for v in vs:
|
||||||
|
deserialized_headers.add(k, v)
|
||||||
|
else:
|
||||||
|
deserialized_headers.add(k, vs)
|
||||||
|
|
||||||
|
return CIMultiDictProxy(deserialized_headers)
|
||||||
|
|
||||||
|
|
||||||
def play_responses(cassette, vcr_request):
|
def play_responses(cassette, vcr_request):
|
||||||
|
|||||||
Reference in New Issue
Block a user