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,19 +1,16 @@
|
||||
from six import BytesIO, text_type
|
||||
from six.moves.urllib.parse import urlparse, urlencode, urlunparse
|
||||
import copy
|
||||
import json
|
||||
|
||||
from .compat import collections
|
||||
|
||||
|
||||
def remove_headers(request, headers_to_remove):
|
||||
headers = copy.copy(request.headers)
|
||||
headers_to_remove = [h.lower() for h in headers_to_remove]
|
||||
keys = [k for k in headers if k.lower() in headers_to_remove]
|
||||
if keys:
|
||||
for k in keys:
|
||||
headers.pop(k)
|
||||
request.headers = headers
|
||||
new_headers = request.headers.copy()
|
||||
for k in headers_to_remove:
|
||||
if k in new_headers:
|
||||
del new_headers[k]
|
||||
request.headers = new_headers
|
||||
return request
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user