From: Andrew M. Kuchling Date: Fri, 22 Dec 2006 19:08:41 +0000 (+0000) Subject: [Patch #827559 from Chris Gonnerman] Make SimpleHTTPServer redirect when a directory... X-Git-Tag: v2.5.1c1~202 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=60775f29de0e6107a46f668144cb1c133d6e5147;p=python [Patch #827559 from Chris Gonnerman] Make SimpleHTTPServer redirect when a directory URL is missing the trailing slash; this lets relative links work. --- diff --git a/Lib/SimpleHTTPServer.py b/Lib/SimpleHTTPServer.py index fae551a565..86c669ea40 100644 --- a/Lib/SimpleHTTPServer.py +++ b/Lib/SimpleHTTPServer.py @@ -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): diff --git a/Misc/NEWS b/Misc/NEWS index dca49c1bba..897346b548 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -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.