[Patch #827559 from Chris Gonnerman] Make SimpleHTTPServer redirect when a directory URL is missing the trailing slash; this lets relative links work.

This commit is contained in:
Andrew M. Kuchling 2006-12-22 19:08:41 +00:00
parent bbad84b41a
commit 60775f29de
2 changed files with 10 additions and 0 deletions

View 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):

View File

@ -125,6 +125,10 @@ Library
- 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.