diff options
-rw-r--r-- | Lib/http/server.py | 1 | ||||
-rw-r--r-- | Lib/test/test_httpservers.py | 1 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2021-04-30-16-58-24.bpo-43972.Y2r9lg.rst | 3 |
3 files changed, 5 insertions, 0 deletions
diff --git a/Lib/http/server.py b/Lib/http/server.py index 94f730e..e985dfd 100644 --- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -689,6 +689,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): parts[3], parts[4]) new_url = urllib.parse.urlunsplit(new_parts) self.send_header("Location", new_url) + self.send_header("Content-Length", "0") 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 6b17817..cb0a3aa 100644 --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -428,6 +428,7 @@ class SimpleHTTPServerTestCase(BaseTestCase): self.check_status_and_reason(response, HTTPStatus.OK) response = self.request(self.base_url) self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY) + self.assertEqual(response.getheader("Content-Length"), "0") response = self.request(self.base_url + '/?hi=2') self.check_status_and_reason(response, HTTPStatus.OK) response = self.request(self.base_url + '?hi=1') diff --git a/Misc/NEWS.d/next/Library/2021-04-30-16-58-24.bpo-43972.Y2r9lg.rst b/Misc/NEWS.d/next/Library/2021-04-30-16-58-24.bpo-43972.Y2r9lg.rst new file mode 100644 index 0000000..3d67b88 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-04-30-16-58-24.bpo-43972.Y2r9lg.rst @@ -0,0 +1,3 @@ +When :class:`http.server.SimpleHTTPRequestHandler` sends a +``301 (Moved Permanently)`` for a directory path not ending with `/`, add a +``Content-Length: 0`` header. This improves the behavior for certain clients. |