From e3b711656496a8bf526836380f9e0e2d496ed22f Mon Sep 17 00:00:00 2001 From: Laurent Mazuel Date: Tue, 30 Jul 2019 16:17:54 -0700 Subject: [PATCH] aiohttp headers are case insensitive (#461) * aiohttp headers are case insensitive * flakes --- tests/integration/test_aiohttp.py | 14 +++++++++++++- vcr/stubs/aiohttp_stubs/__init__.py | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/integration/test_aiohttp.py b/tests/integration/test_aiohttp.py index 1e0f88f..5976b99 100644 --- a/tests/integration/test_aiohttp.py +++ b/tests/integration/test_aiohttp.py @@ -59,12 +59,24 @@ def test_headers(tmpdir, scheme, auth): request = cassette.requests[0] assert "AUTHORIZATION" in request.headers cassette_response, _ = get(url, auth=auth) - assert cassette_response.headers == response.headers + assert dict(cassette_response.headers) == dict(response.headers) assert cassette.play_count == 1 assert 'istr' not in cassette.data[0] assert 'yarl.URL' not in cassette.data[0] +def test_case_insensitive_headers(tmpdir, scheme): + url = scheme + '://httpbin.org' + with vcr.use_cassette(str(tmpdir.join('whatever.yaml'))): + _, _ = get(url) + + with vcr.use_cassette(str(tmpdir.join('whatever.yaml'))) as cassette: + cassette_response, _ = get(url) + assert "Content-Type" in cassette_response.headers + assert "content-type" in cassette_response.headers + assert cassette.play_count == 1 + + def test_text(tmpdir, scheme): url = scheme + '://httpbin.org' with vcr.use_cassette(str(tmpdir.join('text.yaml'))): diff --git a/vcr/stubs/aiohttp_stubs/__init__.py b/vcr/stubs/aiohttp_stubs/__init__.py index 3f0314f..ba659af 100644 --- a/vcr/stubs/aiohttp_stubs/__init__.py +++ b/vcr/stubs/aiohttp_stubs/__init__.py @@ -7,6 +7,7 @@ import logging import json from aiohttp import ClientResponse, streams +from multidict import CIMultiDict, CIMultiDictProxy from yarl import URL from vcr.request import Request @@ -61,7 +62,7 @@ def build_response(vcr_request, vcr_response, history): response.status = vcr_response['status']['code'] response._body = vcr_response['body'].get('string', b'') response.reason = vcr_response['status']['message'] - response._headers = vcr_response['headers'] + response._headers = CIMultiDictProxy(CIMultiDict(vcr_response['headers'])) response._history = tuple(history) response.close()