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):
|
141 | 141 | domain = request.get_host() |
142 | 142 | path = request.get_full_path() |
143 | 143 | referer = request.META.get('HTTP_REFERER', '') |
| 144 | user_agent = request.META.get('HTTP_USER_AGENT', '') |
144 | 145 | is_internal = self.is_internal_request(domain, referer) |
145 | 146 | 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) |
147 | 148 | if referer and (is_internal or is_not_search_engine) and not is_ignorable: |
148 | 149 | ua = request.META.get('HTTP_USER_AGENT', '<none>') |
149 | 150 | ip = request.META.get('REMOTE_ADDR', '<none>') |
… |
… |
class BrokenLinkEmailsMiddleware(object):
|
160 | 161 | # Different subdomains are treated as different domains. |
161 | 162 | return re.match("^https?://%s/" % re.escape(domain), referer) |
162 | 163 | |
163 | | def is_ignorable_404(self, uri): |
| 164 | def is_ignorable_404(self, uri, user_agent=None): |
164 | 165 | """ |
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. |
166 | 167 | """ |
167 | 168 | return any(pattern.search(uri) for pattern in settings.IGNORABLE_404_URLS) |