changeset 5175:ece8d64f8a57

use 301 redirect for some cases
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 02 Oct 2009 23:21:52 +0200
parents e8d4fabc31e2
children c16381dd17fe 84c05e657b47
files MoinMoin/Page.py MoinMoin/action/RenamePage.py MoinMoin/request/__init__.py MoinMoin/request/request_twisted.py
diffstat 4 files changed, 12 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Fri Oct 02 21:02:50 2009 +0200
+++ b/MoinMoin/Page.py	Fri Oct 02 23:21:52 2009 +0200
@@ -1033,7 +1033,7 @@
             redirect_url = Page(request, pagename).url(request,
                                                        querystr={'action': 'show', 'redirect': self.page_name, },
                                                        anchor=anchor)
-            request.http_redirect(redirect_url)
+            request.http_redirect(redirect_url, status='301')
             return
 
         # if necessary, load the formatter
--- a/MoinMoin/action/RenamePage.py	Fri Oct 02 21:02:50 2009 +0200
+++ b/MoinMoin/action/RenamePage.py	Fri Oct 02 23:21:52 2009 +0200
@@ -73,7 +73,7 @@
     def do_action_finish(self, success):
         if success:
             url = Page(self.request, self.newpagename).url(self.request)
-            self.request.http_redirect(url)
+            self.request.http_redirect(url, status='301')
         else:
             self.render_msg(self.make_form(), "dialog")
 
--- a/MoinMoin/request/__init__.py	Fri Oct 02 21:02:50 2009 +0200
+++ b/MoinMoin/request/__init__.py	Fri Oct 02 23:21:52 2009 +0200
@@ -1189,7 +1189,7 @@
             pg = Page(self, pname)
             if pg.exists():
                 url = pg.url(self)
-                self.http_redirect(url)
+                self.http_redirect(url, status='301')
                 return True
         return False
 
@@ -1332,13 +1332,17 @@
 
         return self.finish()
 
-    def http_redirect(self, url):
+    def http_redirect(self, url, status='302'):
         """ Redirect to a fully qualified, or server-rooted URL
 
         @param url: relative or absolute url, ascii using url encoding.
         """
         url = self.getQualifiedURL(url)
-        self.emit_http_headers(["Status: 302 Found", "Location: %s" % url])
+        header = {
+            "301": "Status: 301 Moved Permanently",
+            "302": "Status: 302 Found",
+        }[status]
+        self.emit_http_headers([header, "Location: %s" % url])
 
     def emit_http_headers(self, more_headers=[], testing=False):
         """ emit http headers after some preprocessing / checking
--- a/MoinMoin/request/request_twisted.py	Fri Oct 02 21:02:50 2009 +0200
+++ b/MoinMoin/request/request_twisted.py	Fri Oct 02 23:21:52 2009 +0200
@@ -129,9 +129,11 @@
             else:
                 self.twistd.setHeader(key, value)
 
-    def http_redirect(self, url):
+    def http_redirect(self, url, status='302'):
         """ Redirect to a fully qualified, or server-rooted URL
 
+        TODO: use status '301' or '302' to generate correct header
+
         @param url: relative or absolute url, ascii using url encoding.
         """
         url = self.getQualifiedURL(url)