]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[Patch #827559 from Chris Gonnerman] Make SimpleHTTPServer redirect when a directory...
authorAndrew M. Kuchling <amk@amk.ca>
Fri, 22 Dec 2006 19:06:16 +0000 (19:06 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Fri, 22 Dec 2006 19:06:16 +0000 (19:06 +0000)
Lib/SimpleHTTPServer.py

index fae551a5659cecd3be5f7d8e182a2b27db767830..86c669ea409ed07b979a46bb75e39c6769136f02 100644 (file)
@@ -66,6 +66,12 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
         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):