Commits

EGh5 committed d1e106c

Bug fix Http404. Improve forgiving logic

  • Participants
  • Parent commits 60c8ebc

Comments (0)

Files changed (1)

File doorkeeper/middleware.py

 
 import datetime
 
-from django.http import HttpResponseNotFound
+from django.http import Http404
 from doorkeeper.models import BotRecord
 from django.conf import settings
 
 class DoorkeeperMiddleware(object):
     def process_request(self, request):
         """
-          Each request is investigated.
+          Each request is investigated - overheads for suspicions
         """
         sagent = request.META.get('HTTP_USER_AGENT',"n/a")
         saddr = request.META.get('REMOTE_ADDR',"n/a")
             br=BotRecord.objects.get(bot_hash=shash) # if client exists in BotRecords
             now=datetime.datetime.now()
             if br.detention_upto:                    # check detention end time
-                if br.detention_upto> now:           # fresh banned client
+                if br.detention_upto> now:           # if it is a fresh banned client
                     raise Http404()                  # bounce - it's active bad bot!
                 else:
                     if br.penalty_count > PATIENCE:  # for old banned client
-                        br.penalty_count=0           # forgiving them
+                        br.penalty_count-=PATIENCE   # forgiving them partly
                         br.save()
                     pass
         except BotRecord.DoesNotExist: