changeset: 93968:e7c7e1fce3e2 parent: 93965:32c5b9aeee82 parent: 93967:3d19f419cc44 user: Benjamin Peterson date: Fri Dec 26 10:56:51 2014 -0600 files: Lib/http/server.py Misc/NEWS description: merge 3.4 (#23112) diff -r 32c5b9aeee82 -r e7c7e1fce3e2 Lib/http/server.py --- a/Lib/http/server.py Thu Dec 25 18:36:56 2014 -0500 +++ b/Lib/http/server.py Fri Dec 26 10:56:51 2014 -0600 @@ -648,10 +648,14 @@ path = self.translate_path(self.path) f = None 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 self.send_response(HTTPStatus.MOVED_PERMANENTLY) - 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() return None for index in "index.html", "index.htm": diff -r 32c5b9aeee82 -r e7c7e1fce3e2 Lib/test/test_httpservers.py --- a/Lib/test/test_httpservers.py Thu Dec 25 18:36:56 2014 -0500 +++ b/Lib/test/test_httpservers.py Fri Dec 26 10:56:51 2014 -0600 @@ -305,6 +305,12 @@ 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 -r 32c5b9aeee82 -r e7c7e1fce3e2 Misc/NEWS --- a/Misc/NEWS Thu Dec 25 18:36:56 2014 -0500 +++ b/Misc/NEWS Fri Dec 26 10:56:51 2014 -0600 @@ -196,6 +196,9 @@ Library ------- +- Issue #23112: Fix SimpleHTTPServer to correctly carry the query string and + fragment when it redirects to add a trailing slash. + - Issue #21793: Added http.HTTPStatus enums (i.e. HTTPStatus.OK, HTTPStatus.NOT_FOUND). Patch by Demian Brecht.