Ticket #20099: patch.patch

File patch.patch, 1.8 KB (added by Ram Rachum, 12 years ago)

Patch

  • django/middleware/common.py

    From a457bf170dbc1d24114d5db7464895b0eb5732f2 Mon Sep 17 00:00:00 2001
    From: Ram Rachum <ram@rachum.com>
    Date: Thu, 21 Mar 2013 18:01:25 +0200
    Subject: [PATCH] Add user_agent argument to
     BrokenLinkEmailsMiddleware.is_ignorable_404
    
    ---
     django/middleware/common.py |    7 ++++---
     1 files changed, 4 insertions(+), 3 deletions(-)
    
    diff --git a/django/middleware/common.py b/django/middleware/common.py
    index 92f8cb3..73a35d6 100644
    a b class BrokenLinkEmailsMiddleware(object):  
    141141            domain = request.get_host()
    142142            path = request.get_full_path()
    143143            referer = request.META.get('HTTP_REFERER', '')
     144            user_agent = request.META.get('HTTP_USER_AGENT', '')
    144145            is_internal = self.is_internal_request(domain, referer)
    145146            is_not_search_engine = '?' not in referer
    146             is_ignorable = self.is_ignorable_404(path)
     147            is_ignorable = self.is_ignorable_404(path, user_agent=user_agent)
    147148            if referer and (is_internal or is_not_search_engine) and not is_ignorable:
    148149                ua = request.META.get('HTTP_USER_AGENT', '<none>')
    149150                ip = request.META.get('REMOTE_ADDR', '<none>')
    class BrokenLinkEmailsMiddleware(object):  
    160161        # Different subdomains are treated as different domains.
    161162        return re.match("^https?://%s/" % re.escape(domain), referer)
    162163
    163     def is_ignorable_404(self, uri):
     164    def is_ignorable_404(self, uri, user_agent=None):
    164165        """
    165         Returns True if a 404 at the given URL *shouldn't* notify the site managers.
     166        Returns True if a 404 at the given URL and user agent *shouldn't* notify the site managers.
    166167        """
    167168        return any(pattern.search(uri) for pattern in settings.IGNORABLE_404_URLS)
Back to Top