summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/SimpleHTTPServer.py9
-rw-r--r--Lib/test/test_httpservers.py6
-rw-r--r--Misc/NEWS3
3 files changed, 16 insertions, 2 deletions
diff --git a/Lib/SimpleHTTPServer.py b/Lib/SimpleHTTPServer.py
index d497e1e..783d0ac 100644
--- a/Lib/SimpleHTTPServer.py
+++ b/Lib/SimpleHTTPServer.py
@@ -14,6 +14,7 @@ import os
import posixpath
import BaseHTTPServer
import urllib
+import urlparse
import cgi
import sys
import shutil
@@ -68,10 +69,14 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
path = self.translate_path(self.path)
f = None
if os.path.isdir(path):
- if not self.path.endswith('/'):
+ parts = urlparse.urlsplit(self.path)
+ if not parts.path.endswith('/'):
# redirect browser - doing basically what apache does
self.send_response(301)
- self.send_header("Location", self.path + "/")
+ new_parts = (parts[0], parts[1], parts[2] + '/',
+ parts[3], parts[4])
+ new_url = urlparse.urlunsplit(new_parts)
+ self.send_header("Location", new_url)
self.end_headers()
return None
for index in "index.html", "index.htm":
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py
index bd26140..706dfc7 100644
--- a/Lib/test/test_httpservers.py
+++ b/Lib/test/test_httpservers.py
@@ -321,6 +321,12 @@ class SimpleHTTPServerTestCase(BaseTestCase):
self.check_status_and_reason(response, 200)
response = self.request(self.tempdir_name)
self.check_status_and_reason(response, 301)
+ response = self.request(self.tempdir_name + '/?hi=2')
+ self.check_status_and_reason(response, 200)
+ response = self.request(self.tempdir_name + '?hi=1')
+ self.check_status_and_reason(response, 301)
+ self.assertEqual(response.getheader("Location"),
+ self.tempdir_name + "/?hi=1")
response = self.request('/ThisDoesNotExist')
self.check_status_and_reason(response, 404)
response = self.request('/' + 'ThisDoesNotExist' + '/')
diff --git a/Misc/NEWS b/Misc/NEWS
index 8d44926..b204aeb 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,6 +15,9 @@ Core and Builtins
Library
-------
+- Issue #23112: Fix SimpleHTTPServer to correctly carry the query string and
+ fragment when it redirects to add a trailing slash.
+
- Issue #23093: In the io, module allow more operations to work on detached
streams.