From b3f35b93c257e4b47edc5c90c8d4c37e0d9a2c52 Mon Sep 17 00:00:00 2001 From: Wagner Bruna Date: Wed, 30 May 2012 20:36:38 +0200 Subject: deal with multiple WWW-Authenticate headers A server supporting both Negotiate and Basic authentication methods could send both headers at once, but the get() method returns only the last one. --- urllib2_kerberos.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/urllib2_kerberos.py b/urllib2_kerberos.py index 2af1afb..b763f35 100644 --- a/urllib2_kerberos.py +++ b/urllib2_kerberos.py @@ -33,16 +33,17 @@ class AbstractKerberosAuthHandler: def negotiate_value(self, headers): """checks for "Negotiate" in proper auth header """ - authreq = headers.get(self.auth_header, None) + authreqs = headers.getheaders(self.auth_header) log.debug('authreqs = %s', authreqs) - if authreq: + if authreqs: rx = re.compile('(?:.*,)*\s*Negotiate\s*([^,]*),?', re.I) - mo = rx.search(authreq) - if mo: - return mo.group(1) - else: - log.debug("regex failed on: %s", authreq) + for authreq in authreqs: + mo = rx.search(authreq) + if mo: + return mo.group(1) + else: + log.debug("regex failed on: %s", authreq) else: log.debug("%s header not found", self.auth_header) -- cgit