1035
1035
# Let's be ready for next round
1036
1036
self._retry_count = None
1038
server_header = headers.get(self.auth_required_header, None)
1039
if server_header is None:
1038
server_headers = headers.getheaders(self.auth_required_header)
1039
if not server_headers:
1040
1040
# The http error MUST have the associated
1041
1041
# header. This must never happen in production code.
1042
1042
raise KeyError('%s not found' % self.auth_required_header)
1044
1044
auth = self.get_auth(request)
1045
1045
auth['modified'] = False
1046
if self.auth_match(server_header, auth):
1047
# auth_match may have modified auth (by adding the
1048
# password or changing the realm, for example)
1049
if (request.get_header(self.auth_header, None) is not None
1050
and not auth['modified']):
1051
# We already tried that, give up
1054
if self.requires_username and auth.get('user', None) is None:
1055
# Without a known user, we can't authenticate
1059
request.connection.cleanup_pipe()
1060
response = self.parent.open(request)
1062
self.auth_successful(request, response)
1046
# FIXME: the auth handler should be selected at a single place instead
1047
# of letting all handlers try to match all headers.
1048
for server_header in server_headers:
1049
# Several schemes can be proposed by the server, try to match each
1051
matching_handler = self.auth_match(server_header, auth)
1052
if matching_handler:
1053
# auth_match may have modified auth (by adding the
1054
# password or changing the realm, for example)
1055
if (request.get_header(self.auth_header, None) is not None
1056
and not auth['modified']):
1057
# We already tried that, give up
1060
if self.requires_username and auth.get('user', None) is None:
1061
# Without a known user, we can't authenticate
1065
request.connection.cleanup_pipe()
1066
# Retry the request with an authentication header added
1067
response = self.parent.open(request)
1069
self.auth_successful(request, response)
1064
1071
# We are not qualified to handle the authentication.
1065
1072
# Note: the authentication error handling will try all
1066
1073
# available handlers. If one of them authenticates
1261
1268
match, realm = self.extract_realm(raw_auth)
1263
if scheme != 'basic':
1266
1270
# Put useful info into auth
1267
1271
self.update_auth(auth, 'scheme', scheme)
1268
1272
self.update_auth(auth, 'realm', realm)