Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improved detection of whether a URL is internal or not for the purpose

of broken link e-mails (referred links from images.google were being
misclassified).


git-svn-id: http://code.djangoproject.com/svn/django/trunk@3870 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 8b216eb8656bfd83b34243189293f6433fdc2b80 1 parent 96f0b7b
@spookylukey spookylukey authored
Showing with 7 additions and 1 deletion.
  1. +7 −1 django/middleware/common.py
View
8 django/middleware/common.py
@@ -2,6 +2,7 @@
from django import http
from django.core.mail import mail_managers
import md5
+import re
class CommonMiddleware(object):
"""
@@ -61,7 +62,7 @@ def process_response(self, request, response):
# send a note to the managers.
domain = http.get_host(request)
referer = request.META.get('HTTP_REFERER', None)
- is_internal = referer and (domain in referer)
+ is_internal = _is_internal_request(domain, referer)
path = request.get_full_path()
if referer and not _is_ignorable_404(path) and (is_internal or '?' not in referer):
ua = request.META.get('HTTP_USER_AGENT', '<none>')
@@ -88,3 +89,8 @@ def _is_ignorable_404(uri):
if uri.endswith(end):
return True
return False
+
+def _is_internal_request(domain, referer):
+ "Return true if the referring URL is the same domain as the current request"
+ # Different subdomains are treated as different domains.
+ return referer is not None and re.match("^https?://%s/" % re.escape(domain), referer)
Please sign in to comment.
Something went wrong with that request. Please try again.