kennethreitz/requests — pull request #1092 by jianlius (2013-01-10 05:42:44+00:00)
Title: Make merge_kwargs case-insensitive when looking up keys.

This GET request spuriously returns a 400

```python
>>> import requests
>>> url = "http://www.stackoverflow.com"
>>> headers ={"User-agent": "Mozilla/5.0"}
>>> response = requests.get(url, headers=headers)
>>> print response.status_code
400
```

This is because ever since a776e7cb3e57e56a2d9974b730e6f5e7776751a4,

```python
headers = merge_kwargs(headers, self.headers)
```

causes the LHS to have two keys for user-agent when the user-supplied version is incorrectly capitalized:

```python
>>> headers.keys()
['Accept-Encoding', 'Accept', 'User-Agent', 'User-agent']
```

A solution is to, instead of using `dict.update`, iterate through each key and update manually using a case-insensitive key lookup. This feels kinda hacky, so please let me know if there is a cleaner way to fix this.