Do not set headers with None value

- Regardless of whether they are on the session or not
- Fixes #1920
This commit is contained in:
Ian Cordasco
2014-02-14 16:15:21 -06:00
parent 3c88e520da
commit d2f647cee4
2 changed files with 10 additions and 0 deletions
+2
View File
@@ -59,6 +59,8 @@ def merge_setting(request_setting, session_setting, dict_class=OrderedDict):
if v is None:
del merged_setting[k]
merged_setting = dict((k, v) for (k, v) in merged_setting.items() if v is not None)
return merged_setting
+8
View File
@@ -211,6 +211,14 @@ class RequestsTestCase(unittest.TestCase):
req_urls = [r.request.url for r in resp.history]
assert urls == req_urls
def test_headers_on_session_with_None_are_not_sent(self):
"""Do not send headers in Session.headers with None values."""
ses = requests.Session()
ses.headers['Accept-Encoding'] = None
req = requests.Request('GET', 'http://httpbin.org/get')
prep = ses.prepare_request(req)
assert 'Accept-Encoding' not in prep.headers
def test_user_agent_transfers(self):
heads = {