From e752455b6f1b5913305a9014f3c0b535ba054069 Mon Sep 17 00:00:00 2001 From: Ovidiu Negrut Date: Mon, 11 Mar 2013 10:28:37 +0200 Subject: [PATCH 1/2] Digest auth: case insensitive replacement of 'digest ' string with '' from WWW-Authenticate --- requests/auth.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requests/auth.py b/requests/auth.py index 805f2400..16546f29 100644 --- a/requests/auth.py +++ b/requests/auth.py @@ -8,6 +8,7 @@ This module contains the authentication handlers for Requests. """ import os +import re import time import hashlib import logging @@ -151,7 +152,7 @@ class HTTPDigestAuth(AuthBase): if 'digest' in s_auth.lower() and num_401_calls < 2: setattr(self, 'num_401_calls', num_401_calls + 1) - self.chal = parse_dict_header(s_auth.replace('Digest ', '')) + self.chal = parse_dict_header(re.sub(r'digest ', '', s_auth, flags=re.IGNORECASE)) # Consume content and release the original connection # to allow our new request to reuse the same one. From 9d16c7276791fb7e5e75f2fbcddec95fa8f15b2b Mon Sep 17 00:00:00 2001 From: Ovidiu Negrut Date: Mon, 25 Mar 2013 12:28:25 +0200 Subject: [PATCH 2/2] compiled regex expression in digest auth, this also works in python 2.6.x --- requests/auth.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requests/auth.py b/requests/auth.py index 16546f29..a6405d32 100644 --- a/requests/auth.py +++ b/requests/auth.py @@ -152,7 +152,8 @@ class HTTPDigestAuth(AuthBase): if 'digest' in s_auth.lower() and num_401_calls < 2: setattr(self, 'num_401_calls', num_401_calls + 1) - self.chal = parse_dict_header(re.sub(r'digest ', '', s_auth, flags=re.IGNORECASE)) + pat = re.compile(r'digest ', flags=re.IGNORECASE) + self.chal = parse_dict_header(pat.sub('', s_auth)) # Consume content and release the original connection # to allow our new request to reuse the same one.