mirror of https://github.com/python/cpython
fix behavior of trailing slash redirection when a query string is involved (closes #23112)
This commit is contained in:
parent
8c4e112afc
commit
94cb7a2429
|
@ -701,10 +701,14 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
|
||||||
path = self.translate_path(self.path)
|
path = self.translate_path(self.path)
|
||||||
f = None
|
f = None
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
if not self.path.endswith('/'):
|
parts = urllib.parse.urlsplit(self.path)
|
||||||
|
if not parts.path.endswith('/'):
|
||||||
# redirect browser - doing basically what apache does
|
# redirect browser - doing basically what apache does
|
||||||
self.send_response(301)
|
self.send_response(301)
|
||||||
self.send_header("Location", self.path + "/")
|
new_parts = (parts[0], parts[1], parts[2] + '/',
|
||||||
|
parts[3], parts[4])
|
||||||
|
new_url = urllib.parse.urlunsplit(new_parts)
|
||||||
|
self.send_header("Location", new_url)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
return None
|
return None
|
||||||
for index in "index.html", "index.htm":
|
for index in "index.html", "index.htm":
|
||||||
|
|
|
@ -305,6 +305,12 @@ class SimpleHTTPServerTestCase(BaseTestCase):
|
||||||
self.check_status_and_reason(response, 200)
|
self.check_status_and_reason(response, 200)
|
||||||
response = self.request(self.tempdir_name)
|
response = self.request(self.tempdir_name)
|
||||||
self.check_status_and_reason(response, 301)
|
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')
|
response = self.request('/ThisDoesNotExist')
|
||||||
self.check_status_and_reason(response, 404)
|
self.check_status_and_reason(response, 404)
|
||||||
response = self.request('/' + 'ThisDoesNotExist' + '/')
|
response = self.request('/' + 'ThisDoesNotExist' + '/')
|
||||||
|
|
|
@ -41,6 +41,9 @@ Core and Builtins
|
||||||
Library
|
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
|
- Issue #23093: In the io, module allow more operations to work on detached
|
||||||
streams.
|
streams.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue