def process_response(self, request, response):
process = False<EOL>if not self.allow_http and not request.is_secure():<EOL><INDENT>return response<EOL><DEDENT>if response.status_code == UNAUTHORIZED:<EOL><INDENT>pass<EOL><DEDENT>elif response.status_code == FOUND:<EOL><INDENT>location = urllib_parse.urlparse(response['<STR_LIT>'])<EOL>if location.path != settings.LOGIN_URL:<EOL><INDENT>return response<EOL><DEDENT>elif not self.is_agent_a_robot(request):<EOL><INDENT>return response<EOL><DEDENT><DEDENT>realm = getattr(settings, '<STR_LIT>', request.META.get('<STR_LIT>', '<STR_LIT>'))<EOL>if response.status_code == FOUND:<EOL><INDENT>response = self.unauthorized_view(request)<EOL><DEDENT>authenticate = response.get('<STR_LIT>', None)<EOL>if authenticate:<EOL><INDENT>authenticate = '<STR_LIT>' % (realm, authenticate)<EOL><DEDENT>else:<EOL><INDENT>authenticate = '<STR_LIT>' % realm<EOL><DEDENT>response['<STR_LIT>'] = authenticate<EOL>return response<EOL>
Adds WWW-Authenticate: Basic headers to 401 responses, and rewrites
redirects the login page to be 401 responses if it's a non-browser
agent.