Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Do not set headers with None value

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 9a14086, d2f647c · Browse files · 2 files+10 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+10 added−0 removed

  • other:+10 added−0 removed

2 files+10 added−0 removed

modified:requests/sessions.py+2 added
57 unmodified lines
58 for (k, v) in request_setting.items():59 if v is None:60 del merged_setting[k]6162 merged_setting = dict((k, v) for (k, v) in merged_setting.items() if v is not None)6364 return merged_setting656667def merge_hooks(request_hooks, session_hooks, dict_class=OrderedDict):
504 unmodified lines
modified:test_requests.py+8 added
209 unmodified lines
210 urls = [r.url for r in resp.history]211 req_urls = [r.request.url for r in resp.history]212 assert urls == req_urls213214 def test_headers_on_session_with_None_are_not_sent(self):215 """Do not send headers in Session.headers with None values."""216 ses = requests.Session()217 ses.headers['Accept-Encoding'] = None218 req = requests.Request('GET', 'http://httpbin.org/get')219 prep = ses.prepare_request(req)220 assert 'Accept-Encoding' not in prep.headers221222 def test_user_agent_transfers(self):223224 heads = {225 'User-agent': 'Mozilla/5.0 (github.com/kennethreitz/requests)'
958 unmodified lines