'Takes the given response and tries digest-auth, if needed.'

def handle_401(self, r, **kwargs):

    num_401_calls = getattr(self, 'num_401_calls', 1)
    s_auth = r.headers.get('www-authenticate', '')
    if (('digest' in s_auth.lower()) and (num_401_calls < 2)):
        setattr(self, 'num_401_calls', (num_401_calls + 1))
        pat = re.compile('digest    ', flags=re.IGNORECASE)
        self.chal = parse_dict_header(pat.sub('', s_auth, count=1))
        r.content
        r.raw.release_conn()
        r.request.headers['Authorization'] = self.build_digest_header(r.request.method, r.request.url)
        _r = r.connection.send(r.request, **kwargs)
        _r.history.append(r)
        return _r
    setattr(self, 'num_401_calls', 1)
    return r
