Merge pull request #1149 from benoitc/fix/gh1148

check if the auth type is Basic before getting the user name
This commit is contained in:
Benoit Chesneau 2015-11-21 12:10:27 +01:00
commit f74dd0aa3c

View File

@ -4,6 +4,7 @@
# See the NOTICE for more information.
import base64
import binascii
import time
import logging
logging.Logger.manager.emittedNoHandlerWarning = 1
@ -381,7 +382,7 @@ class Logger(object):
def _get_user(self, environ):
user = None
http_auth = environ.get("HTTP_AUTHORIZATION")
if http_auth:
if http_auth and http_auth.startswith('Basic'):
auth = http_auth.split(" ", 1)
if len(auth) == 2:
try:
@ -394,6 +395,9 @@ class Logger(object):
except TypeError as exc:
self.debug("Couldn't get username: %s", exc)
return user
except binascii.Error as exc:
self.debug("Couldn't get username: %s", exc)
return user
if len(auth) == 2:
user = auth[0]
return user