From a6360ca134623a9faecfe64b51e86f42bffb4dd9 Mon Sep 17 00:00:00 2001 From: Juan Riaza Date: Tue, 22 Jan 2013 16:35:16 +0100 Subject: [PATCH] missing algorithm field --- requests/auth.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/requests/auth.py b/requests/auth.py index 277e601..bf6465c 100644 --- a/requests/auth.py +++ b/requests/auth.py @@ -68,18 +68,21 @@ class HTTPDigestAuth(AuthBase): realm = self.chal['realm'] nonce = self.chal['nonce'] qop = self.chal.get('qop') - algorithm = self.chal.get('algorithm', 'MD5') - opaque = self.chal.get('opaque', None) + algorithm = self.chal.get('algorithm') + opaque = self.chal.get('opaque') - algorithm = algorithm.upper() + if algorithm is None: + _algorithm = 'MD5' + else: + _algorithm = algorithm.upper() # lambdas assume digest modules are imported at the top level - if algorithm == 'MD5': + if _algorithm == 'MD5': def md5_utf8(x): if isinstance(x, str): x = x.encode('utf-8') return hashlib.md5(x).hexdigest() hash_utf8 = md5_utf8 - elif algorithm == 'SHA': + elif _algorithm == 'SHA': def sha_utf8(x): if isinstance(x, str): x = x.encode('utf-8') @@ -129,9 +132,10 @@ class HTTPDigestAuth(AuthBase): 'response="%s"' % (self.username, realm, nonce, path, respdig) if opaque: base += ', opaque="%s"' % opaque + if algorithm: + base += ', algorithm="%s"' % algorithm if entdig: base += ', digest="%s"' % entdig - base += ', algorithm="%s"' % algorithm if qop: base += ', qop=auth, nc=%s, cnonce="%s"' % (ncvalue, cnonce) -- 2.7.4