]> granicus.if.org Git - python/commitdiff
Patch #727483: Add AUTH_TYPE and REMOTE_USER.
authorMartin v. Löwis <martin@v.loewis.de>
Sun, 29 Aug 2004 16:53:26 +0000 (16:53 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Sun, 29 Aug 2004 16:53:26 +0000 (16:53 +0000)
Lib/CGIHTTPServer.py

index f7b772268daad255408d65ad74e6f15a75f5f867..47a0e2c37a6eb38cc806a0aa65f65028e303bc96 100644 (file)
@@ -153,8 +153,21 @@ class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
         if host != self.client_address[0]:
             env['REMOTE_HOST'] = host
         env['REMOTE_ADDR'] = self.client_address[0]
-        # XXX AUTH_TYPE
-        # XXX REMOTE_USER
+        authorization = self.headers.getheader("authorization")
+        if authorization:
+            authorization = authorization.split()
+            if len(authorization) == 2:
+                import base64, binascii
+                env['AUTH_TYPE'] = authorization[0]
+                if authorization[0].lower() == "basic":
+                    try:
+                        authorization = base64.decodestring(authorization[1])
+                    except binascii.Error:
+                        pass
+                    else:
+                        authorization = authorization.split(':')
+                        if len(authorization) == 2:
+                            env['REMOTE_USER'] = authorization[0]
         # XXX REMOTE_IDENT
         if self.headers.typeheader is None:
             env['CONTENT_TYPE'] = self.headers.type