Change _store of CaseInsensitiveDict to OrderedDict

This will preserve order of request headers when passed to request method as `OrderedDict`.

Closes #3038.


Thanks for this! I'd love a test that proves that this works: do you feel like you're up to writing one?


OK, now tests should pass on Python 2.6 as well.


@piotrjurkiewicz the tests fail on 3.3 and 3.4 now http://ci.kennethreitz.org/job/requests-pr/974/

This reminds me, I need to add Python 3.5 to the CI server. I didn't realize it was missing. 


@kennethreitz the tests here seem to have hung in Jenkins. Is there anyway to add a timeout to test runs?


@sigmavirus24 just added a build timeout plugin, configured for 5 minutes for PR builds. 

Don't worry, I'm getting increasingly frustrated with maintaining Jenkins at the moment. 


> Don't worry, I'm getting increasingly frustrated with maintaining Jenkins at the moment. 

I've been maintaining my own for a while. I feel your pain and I'm happy to help out more.


I mean, I've been managing Jenkins servers since the Hudson days, but this is the only one I've had to deal with in the past three years, and my annoyances with how it requires at least some level of upkeep are growing :)

I do think it's an overall less frustrating experience for this project than using Travis would be, so worth the effort. Travis has seen much improvements over the past two years, though, so at some point, this may no longer be true. 


:sparkles: :cake: :sparkles:


Is this fixed in version 2.10.0 ?

```
import requests
from collections import OrderedDict



headers = OrderedDict( [
('User-Agent', 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0'),
('Accept', 'application/json, text/javascript, */*; q=0.01'),
('Accept-Language', 'cs,en-US;q=0.7,en;q=0.3'),
('Accept-Encoding', 'gzip, deflate'),
('Connection', 'keep-alive'),
] )

rsp = requests.get('http://api.wipmania.com',headers=headers)

```

order of headers not preserved on Windows 8.1  python 2.7.9   tested with Wireshark

edit: it seems to work fine only if I use session like this

```
import requests
from collections import OrderedDict

headers = OrderedDict( [
('User-Agent', 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0'),
('Accept', 'application/json, text/javascript, */*; q=0.01'),
('Accept-Language', 'cs,en-US;q=0.7,en;q=0.3'),
('Accept-Encoding', 'gzip, deflate'),
('Connection', 'keep-alive'),
] )

ses = requests.Session()
ses.headers = OrderedDict()
ses.get('http://website.com',headers=headers)
```


The reason the header order is being overridden in your case is because of the way requests merges the two different dictionaries in the `Session` and the request kwargs.

By default, a requests `Session` already contains several keys:

```
>>> s = requests.Session()
>>> s.headers
{'Connection': 'keep-alive', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.10.0'}
```

You'll note, then, that when you send headers using the `headers` kwarg, the order of the keys in the Session is preserved in priority to the order of the keys in the `headers` kwarg. This is the expected result of using the dict on the `Session` as the base into which the request dict is merged to update.

Trying to get the entirely intuitive behaviour (where the request header defines the order in preference to the `Session` order) is somewhat frustrating. Right now the code looks like this:

``` python
actual_headers = CaseInsensitiveDict(to_key_val_list(session.headers))
actual_headers.update(to_key_val_list(request.headers))
```

We'd need to change the code to

``` python
actual_headers = CaseInsensitiveDict(to_key_val_list(request.headers))
actual_headers.update(to_key_val_list(session.headers))
actual_headers.update(to_key_val_list(request.headers))
```

This would lead to the exact same result as we currently have but would prioritise the _order_ of the request dict rather than the `Session` dict. The cost is that we do substantially extra computation in order to achieve this relatively minor effect.

I am open to making this change, but it does rather feel like using a sledgehammer to crack a nut. @kennethreitz @sigmavirus24?


@Lukasa I think this is something we need to document instead of work around. I'm not sure "fixing" that particular behaviour wouldn't introduce some other subtle bug.


I don't disagree with @sigmavirus24. While I do feel like this pattern should "just work" as requested, I feel like it's extremely uncommon for someone to want/need this, and we should not bend over backwards to accomplish this. 


Ok, so I think we're in agreement: we'd rather document this than try to change the logic.