Blob Blame History Raw
# HG changeset patch
# User Wagner Bruna <wbruna@softwareexpress.com.br>
# Date 1338402998 10800
# Node ID 5e53d94fdf9cb73304790a38ba24b19415de73ea
# Parent  08f4f4f83058d9896a0debc2ff3899a9a358f942
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.

--- a/urllib2_kerberos.py
+++ b/urllib2_kerberos.py
@@ -41,15 +41,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)
+
+        if authreqs:

-        if authreq:
             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)