diff options
| author | harikrishnakanchi <harikrishnakanchi@gmail.com> | 2016-01-22 00:53:51 +0530 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-03-08 09:21:42 -0500 |
| commit | 74670498e902a0506e667cd21084c5e2eb71edfa (patch) | |
| tree | 6c931ace0b079531e522ab44185bf7e5c687aa99 /django/middleware/common.py | |
| parent | 6c33e7333336487a30dbd170c93b2f6e50133de7 (diff) | |
Fixed #25971 -- Made BrokenLinkEmailsMiddleware ignore APPEND_SLASH redirects.
If APPEND_SLASH=True and the referer is the URL without a trailing '/', then
BrokenLinkEmailsMiddleware shouldn't send an email.
Diffstat (limited to 'django/middleware/common.py')
| -rw-r--r-- | django/middleware/common.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/django/middleware/common.py b/django/middleware/common.py index 948b76c71b..70d8c57f7e 100644 --- a/django/middleware/common.py +++ b/django/middleware/common.py @@ -162,18 +162,24 @@ class BrokenLinkEmailsMiddleware(object): def is_ignorable_request(self, request, uri, domain, referer): """ Return True if the given request *shouldn't* notify the site managers - according to project settings or in three specific situations: - - If the referer is empty. - - If a '?' in referer is identified as a search engine source. - - If the referer is equal to the current URL, ignoring the scheme - (assumed to be a poorly implemented bot). + according to project settings or in situations outlined by the inline + comments. """ + # The referer is empty. if not referer: return True + # APPEND_SLASH is enabled and the referer is equal to the current URL + # without a trailing slash indicating an internal redirect. + if settings.APPEND_SLASH and uri.endswith('/') and referer == uri[:-1]: + return True + + # A '?' in referer is identified as a search engine source. if not self.is_internal_request(domain, referer) and '?' in referer: return True + # The referer is equal to the current URL, ignoring the scheme (assumed + # to be a poorly implemented bot). parsed_referer = urlparse(referer) if parsed_referer.netloc in ['', domain] and parsed_referer.path == uri: return True |
