mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-08 16:53:23 +00:00
Make request.headers always a CaseInsensitiveDict.
Previously request.headers was a normal dict (albeit with the request.add_header interface) which meant that some code paths would do case-sensitive matching, for example remove_post_data_parameters which tests for 'Content-Type'. This change allows all code paths to get the same case-insensitive treatment. Additionally request.headers becomes a property to enforce upgrading it to a CaseInsensitiveDict even if assigned.
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
from six import BytesIO, text_type
|
||||
from six.moves.urllib.parse import urlparse, parse_qsl
|
||||
from .util import CaseInsensitiveDict
|
||||
|
||||
|
||||
class Request(object):
|
||||
"""
|
||||
VCR's representation of a request.
|
||||
VCR's representation of a request.
|
||||
|
||||
There is a weird quirk in HTTP. You can send the same header twice. For
|
||||
this reason, headers are represented by a dict, with lists as the values.
|
||||
@@ -32,9 +33,19 @@ class Request(object):
|
||||
self.body = body.read()
|
||||
else:
|
||||
self.body = body
|
||||
self.headers = {}
|
||||
for key in headers:
|
||||
self.add_header(key, headers[key])
|
||||
self.headers = CaseInsensitiveDict()
|
||||
for key, value in headers.items():
|
||||
self.add_header(key, value)
|
||||
|
||||
@property
|
||||
def headers(self):
|
||||
return self._headers
|
||||
|
||||
@headers.setter
|
||||
def headers(self, value):
|
||||
if not isinstance(value, CaseInsensitiveDict):
|
||||
value = CaseInsensitiveDict(value)
|
||||
self._headers = value
|
||||
|
||||
@property
|
||||
def body(self):
|
||||
|
||||
Reference in New Issue
Block a user