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

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

    if (self.pos is not None):
        r.request.body.seek(self.pos)
    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)):
        self.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()
        prep = r.request.copy()
        extract_cookies_to_jar(prep._cookies, r.request, r.raw)
        prep.prepare_cookies(prep._cookies)
        prep.headers['Authorization'] = self.build_digest_header(prep.method, prep.url)
        _r = r.connection.send(prep, **kwargs)
        _r.history.append(r)
        _r.request = prep
        return _r
    self.num_401_calls = 1
    return r
