diff options
author | Stephen Rosen <sirosen@globus.org> | 2021-05-06 19:25:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-06 19:25:52 (GMT) |
commit | fb427255614fc1f740e7785554c1da8ca39116c2 (patch) | |
tree | 00c72b2b79fc0a1fcd649a43e1780b5e13a78f97 /Lib/http/server.py | |
parent | 329a47f0524e9d3f43f1e28c4f9e7c088662c030 (diff) | |
download | cpython-fb427255614fc1f740e7785554c1da8ca39116c2.zip cpython-fb427255614fc1f740e7785554c1da8ca39116c2.tar.gz cpython-fb427255614fc1f740e7785554c1da8ca39116c2.tar.bz2 |
bpo-43972: Set content-length to 0 for http.server.SimpleHTTPRequestHandler 301s (GH-25705)
* Set content-length for simple http server 301s
When http.server.SimpleHTTPRequestHandler sends a 301 (Moved
Permanently) due to a missing file, it does not set a Content-Length
of 0. Unfortunately, certain clients can be left waiting for the
connection to be closed in this circumstance, even though no body
will be sent. At time of writing, both curl and Firefox demonstrate
this behavior.
* Test Content-Length on simple http server redirect
When serving a redirect, the SimpleHTTPRequestHandler will now send
`Content-Length: 0`. Several tests for http.server already cover
various behaviors and checks including redirection. This change only
adds one check for the expected Content-Length on the simplest case
for a redirect.
* Add news entry for SimpleHTTPRequestHandler fix
* Clarify the specific kind of 301
Co-authored-by: Senthil Kumaran <skumaran@gatech.edu>
Diffstat (limited to 'Lib/http/server.py')
-rw-r--r-- | Lib/http/server.py | 1 |
1 files changed, 1 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": |