Permalink
Browse files

Do not set headers with None value

- Regardless of whether they are on the session or not
- Fixes #1920
  • Loading branch information...
1 parent 3c88e52 commit d2f647cee45fd05cc1977cc3faf4b095b5047b29 @sigmavirus24 sigmavirus24 committed Feb 14, 2014
Showing with 10 additions and 0 deletions.
  1. +2 −0 requests/sessions.py
  2. +8 −0 test_requests.py
View
@@ -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
View
@@ -211,6 +211,14 @@ def test_requests_in_history_are_not_overridden(self):
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 = {

0 comments on commit d2f647c

Please sign in to comment.