]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
bpo-43972: Set content-length to 0 for http.server.SimpleHTTPRequestHandler 301s...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 6 May 2021 19:50:54 +0000 (12:50 -0700)
committerGitHub <noreply@github.com>
Thu, 6 May 2021 19:50:54 +0000 (12:50 -0700)
commitb391b9b9255697ce6028bb4e7a99c18080aa991c
treeebe87e90a17435208faee33a5bf8030efb7e3c29
parentce47addfb6f176fad053431b537b77a5f170765e
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>
(cherry picked from commit fb427255614fc1f740e7785554c1da8ca39116c2)

Co-authored-by: Stephen Rosen <sirosen@globus.org>
Lib/http/server.py
Lib/test/test_httpservers.py
Misc/NEWS.d/next/Library/2021-04-30-16-58-24.bpo-43972.Y2r9lg.rst [new file with mode: 0644]