kennethreitz/requests — pull request #1321 by shaung (2013-04-24 12:47:13+00:00)
Title: Clear preset request headers case-insensitively

While request headers can be removed by setting them to `None`:

>>> r = requests.get('http://github.com', headers={'Accept-Encoding': None})
>>> 'Accept-Encoding' in r.request.headers
False

the following code gives an `KeyError` instead of doing the same job:

>>> # Remove preset header
>>> r = requests.get('http://github.com', headers={'accept-encoding': None})
Traceback (most recent call last):
(...)
File "..\requests\sessions.py", line 313, in request
headers = merge_kwargs(headers, self.headers)
File "..\requests\sessions.py", line 76, in merge_kwargs
del kwargs[k]
File "..\requests\packages\urllib3\packages\ordered_dict.py", line 59, in __delitem__
dict_delitem(self, key)
KeyError: 'accept-encoding'

With this patch the key to remove can be specified case-insensitively.

>>> r = requests.get('http://github.com', headers={'accept-encoding': None})
>>> 'Accept-Encoding' in r.request.headers
False