Permalink
Browse files

Merge pull request #1921 from sigmavirus24/fix-session-header-none

Do not set headers with None value
  • Loading branch information...
2 parents 9a14086 + d2f647c commit 3c4b3747e45318ba8df2224fea13895e5210915f @kennethreitz kennethreitz committed Mar 3, 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 3c4b374

Please sign in to comment.