Django

Code

Ticket #1117 (closed: fixed)

Opened 3 years ago

Last modified 2 years ago

add a standard http response for permanent redirect

Reported by: hugo Assigned to: adrian
Milestone: Component: Internationalization
Version: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description (Last modified by hugo)

HttpResponseRedirect uses 302 as it's status code. That's FOUND, not MOVED PERMANTLY - the latter is 301. For that there is no prebuilt response, but it should be added (because in many cases it is much more appropriate to tell the client to use the new URL and forget about the old one). This little patch adds a 301 status code:

Index: utils/httpwrappers.py
===================================================================
--- utils/httpwrappers.py       (revision 1779)
+++ utils/httpwrappers.py       (working copy)
@@ -212,6 +212,12 @@
         self['Location'] = redirect_to
         self.status_code = 302
 
+class HttpResponsePermanentRedirect(HttpResponse):
+    def __init__(self, redirect_to):
+        HttpResponse.__init__(self)
+        self['Location'] = redirect_to
+        self.status_code = 301
+
 class HttpResponseNotModified(HttpResponse):
     def __init__(self):
         HttpResponse.__init__(self)

Situations where we do fixed redirects - for example those done by the CommonMiddleware? - should actually use 301 instead of 302.

Attachments

Change History

12/26/05 08:35:11 changed by hugo

  • description changed.

01/03/06 17:57:15 changed by adrian

  • status changed from new to closed.
  • resolution set to fixed.

07/07/06 15:11:22 changed by anonymous

  • priority changed from normal to high.
  • type changed from defect to enhancement.
  • component changed from Core framework to Internationalization.
  • severity changed from normal to trivial.

Add/Change #1117 (add a standard http response for permanent redirect)




Change Properties
Action