[Python-checkins] r53148 - in python/branches/release25-maint: Lib/SimpleHTTPServer.py Misc/NEWS

andrew.kuchling python-checkins at python.org
Fri Dec 22 20:08:42 CET 2006


Author: andrew.kuchling
Date: Fri Dec 22 20:08:41 2006
New Revision: 53148

Modified:
   python/branches/release25-maint/Lib/SimpleHTTPServer.py
   python/branches/release25-maint/Misc/NEWS
Log:
[Patch #827559 from Chris Gonnerman] Make SimpleHTTPServer redirect when a directory URL is missing the trailing slash; this lets relative links work.

Modified: python/branches/release25-maint/Lib/SimpleHTTPServer.py
==============================================================================
--- python/branches/release25-maint/Lib/SimpleHTTPServer.py	(original)
+++ python/branches/release25-maint/Lib/SimpleHTTPServer.py	Fri Dec 22 20:08:41 2006
@@ -66,6 +66,12 @@
         path = self.translate_path(self.path)
         f = None
         if os.path.isdir(path):
+            if not self.path.endswith('/'):
+                # redirect browser - doing basically what apache does
+                self.send_response(301)
+                self.send_header("Location", self.path + "/")
+                self.end_headers()
+                return None
             for index in "index.html", "index.htm":
                 index = os.path.join(path, index)
                 if os.path.exists(index):

Modified: python/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS	(original)
+++ python/branches/release25-maint/Misc/NEWS	Fri Dec 22 20:08:41 2006
@@ -125,6 +125,10 @@
 - Bug #737202: Make CGIHTTPServer work for scripts in subdirectories.
   Fix by Titus Brown.
 
+- Patch #827559: Make SimpleHTTPServer redirect when a directory URL
+  is missing the trailing slash, so that relative links work correctly.
+  Patch by Chris Gonnerman.
+
 - Patch #1608267: fix a race condition in os.makedirs() is the directory
   to be created is already there.
 


More information about the Python-checkins mailing list