'Check for denied User-Agents and rewrite the URL based on
settings.APPEND_SLASH and settings.PREPEND_WWW'

def process_request(self, request):

    if ('HTTP_USER_AGENT' in request.META):
        for user_agent_regex in settings.DISALLOWED_USER_AGENTS:
            if user_agent_regex.search(request.META['HTTP_USER_AGENT']):
                raise PermissionDenied('Forbidden    user    agent')
    host = request.get_host()
    must_prepend = (settings.PREPEND_WWW and host and (not host.startswith('www.')))
    redirect_url = (('%s://www.%s' % (request.scheme, host)) if must_prepend else '')
    if self.should_redirect_with_slash(request):
        path = self.get_full_path_with_slash(request)
    else:
        path = request.get_full_path()
    if (redirect_url or (path != request.get_full_path())):
        redirect_url += path
        return self.response_redirect_class(redirect_url)
