Redirect messageid urls with slashes in them
authorMagnus Hagander <magnus@hagander.net>
Fri, 28 Dec 2012 13:59:26 +0000 (14:59 +0100)
committerMagnus Hagander <magnus@hagander.net>
Fri, 28 Dec 2012 13:59:26 +0000 (14:59 +0100)
Instead of showing an error, redirect the user back to the correct URL.
These should never be linked, but can show up if you navigate via a 404
page, as shown by Jonathan Katz.

django/archives/mailarchives/views.py
django/archives/urls.py

index a5f646ecda5b1f0d87ca227b518344370750a7a6..e267fca0637d92e274db23ac39c1644c183f49f6 100644 (file)
@@ -442,3 +442,12 @@ def legacy(request, listname, year, month, msgnum):
 @cache(hours=8)
 def mbox(request, listname, mboxname):
        return HttpResponse('This needs to be handled by the webserver. This view should never be called.', content_type='text/plain')
+
+# Redirect to the requested url, with a slash first. This is used to remove
+# trailing slashes on messageid links by doing a permanent redirect. This is
+# better than just eating them, since this way we only end up with one copy
+# in the cache.
+@cache(hours=8)
+def slash_redirect(request, url):
+       print url
+       return HttpResponsePermanentRedirect("/%s" % url)
index 7e7d02dab028209c4d58c76ed32ccf354ceca3d2..347cac3b0dbad969e414333ee3b122f5b0c033c2 100644 (file)
@@ -24,6 +24,9 @@ urlpatterns = patterns('',
     (r'^message-id/raw/([^/]+)$', 'archives.mailarchives.views.message_raw'),
     (r'^archives-search/', 'archives.mailarchives.views.search'),
 
+    # message-id with a slash needs to be redirected to one without it
+    (r'^(message-id/.*)/$', 'archives.mailarchives.views.slash_redirect'),
+
     # Date etc indexes
     (r'^list/([\w-]+)/$', 'archives.mailarchives.views.monthlist'),
     (r'^list/([\w-]+)/(\d+)-(\d+)/$', 'archives.mailarchives.views.datelist'),