@@ -163,20 +163,28 @@ class HttpDigestAuthorization(object):
163163 re-calculation of the digest.
164164 """
165165
166+ scheme = 'digest'
167+
166168 def errmsg (self , s ):
167169 return 'Digest Authorization header: %s' % s
168170
171+ @classmethod
172+ def matches (cls , header ):
173+ scheme , _ , _ = header .partition (' ' )
174+ return scheme .lower () == cls .scheme
175+
169176 def __init__ (
170177 self , auth_header , http_method ,
171178 debug = False , accept_charset = DEFAULT_CHARSET [:],
172179 ):
173180 self .http_method = http_method
174181 self .debug = debug
175- scheme , params = auth_header .split (' ' , 1 )
176- self .scheme = scheme .lower ()
177- if self .scheme != 'digest' :
182+
183+ if not self .matches (auth_header ):
178184 raise ValueError ('Authorization scheme is not "Digest"' )
179185
186+ scheme , params = auth_header .split (' ' , 1 )
187+
180188 self .auth_header = auth_header
181189
182190 # make a dict of the params
@@ -407,8 +415,9 @@ def digest_auth(realm, get_ha1, key, debug=False, accept_charset='utf-8'):
407415 respond_401 = functools .partial (
408416 _respond_401 , realm , key , accept_charset , debug )
409417
410- if auth_header is None :
418+ if not HttpDigestAuthorization . matches ( auth_header or '' ) :
411419 respond_401 ()
420+
412421 msg = 'The Authorization header could not be parsed.'
413422 with cherrypy .HTTPError .handle (ValueError , 400 , msg ):
414423 auth = HttpDigestAuthorization (
0 commit comments