HTTP Digest Auth case insensitive replacement of "Digest "

Hi,

I've encountered this error:

```
File "/sites/.ro-api/api/local/lib/python2.7/site-packages/requests/api.py", line 87, in post
  return request('post', url, data=data, **kwargs)
File "/sites/.ro-api/api/local/lib/python2.7/site-packages/requests/api.py", line 44, in request
  return session.request(method=method, url=url, **kwargs)
File "/sites/.ro-api/api/local/lib/python2.7/site-packages/requests/sessions.py", line 279, in request
  resp = self.send(prep, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies) 
File "/sites/.ro-api/api/local/lib/python2.7/site-packages/requests/sessions.py", line 374, in send 
  r = adapter.send(request, **kwargs)
File "/sites/.ro-api/api/local/lib/python2.7/site-packages/requests/adapters.py", line 219, in send
  r = self.build_response(request, resp)
File "/sites/.ro-api/api/local/lib/python2.7/site-packages/requests/adapters.py", line 113, in build_response 
  response = dispatch_hook('response', req.hooks, response)
File "/sites/.ro-api/api/local/lib/python2.7/site-packages/requests/hooks.py", line 39, in dispatch_hook
  _hook_data = hook(hook_data)
File "/sites/.ro-api/api/local/lib/python2.7/site-packages/requests/auth.py", line 155, in handle_401
  r.request.headers['Authorization'] = self.build_digest_header(r.request.method, r.request.url)
File "/sites/.ro-api/api/local/lib/python2.7/site-packages/requests/auth.py", line 69, in build_digest_header
  nonce = self.chal['nonce']
KeyError: 'nonce'
```

While investigating i found that the site was sending me the following string:
`"WWW-Authenticate: digest nonce="***********************", qop="auth", realm="***************", algorithm="md5", opaque="*******************=""`
The parsed key in this case was: "digest nonce" and not "nonce", thus, the error above.

So I've modified the s_auth in requests/auth.py (line 154) string to replace "Digest " or "digest " with '' using re module and re.sub function. I've tested the feature and it works.

Regards,
Ovidiu Negrut


I hate web server authors. :angry: 

This is a good patch. =) My only question is whether we need the overhead of a regular expression here? @sigmavirus24?


Thanks for the reply... Yes, I've thought of that also, but I'm thinking that if another "web server author" will send a string like 'DiGEst' or another combination of lower and upper letters, the patch will stand.


Fair enough. In that case, I'm +1.


Sorry @Lukasa I've been pretty sick for the past few days. I'll take a look later this week I hope. I would think though that the standard string operations would be enough and provide less overhead than a regular expression. 


@sigmavirus24 All this can be done with standard string operations, but you would have to implement parts of what the re module already has. It would be easy if we could just do a s_auth.lower() on the whole thing and replace what we need, but the case on the rest of the string is important.

The way I see it there are 2 choices. Either we use the re module, or we add code to do a case insensitive replace in requests itself. Basically its a choice between overhead (which I'm not convinced is much) and code complexity. :)
Pisses me off that web server developers don't read the damn standards before implementing something :angry: . 

P.S. Get better soon! :D


Eh, let's just do it twice. 

```
s_auth.replace('Digest ', '').replace('digest ', '')
```


Awesome :). Lets just hope some ding-bat doesn't decide to get creative with the case. I swear, if I ever see "DiGeSt nonce" in a header somewhere, I will track down the author and make him listen to Justin Bieber for a whole hour!


There's a fine line between misreading the spec and being willfully disruptive, and anyone doing "DiGeSt" is a long, long, _long_ way from that line. We don't have to worry about digest auth failing in those cases. =)


@kennethreitz you need to update .travis.yml


already done


This apparently breaks Requests on Python 2.6 :(


Yeah this could be done the way I suggested, or you could compile the regular expression first, e.g.,

``` python
import re

r = re.compile('digest ', re.IGNORECASE)
r.sub('', s_auth)
```


added the code like sigmavirus24 suggested.


@kennethreitz this looks good.


Thanks!