New submission from Stephen Rosen <siro...@globus.org>:

If you use the `http.server` simple server and handler to serve a directory, 
navigating to a directory name without a trailing slash will trigger a 301 to 
add the trailing slash.

For example, if "foo/" is a directory under the file server, a GET for "/foo" 
will receive a 301 Moved Permanently response with a Location header pointing 
at "/foo/".

However, the response is sent without a "Content-Length: 0" and the connection 
is not closed. Unfortunately, certain clients will hang indefinitely and wait 
under these conditions, without processing the redirect. In my testing, curl 
7.68 and Firefox 87 both exhibted this behavior.

If a Content-Length header is set, these clients behave correctly.
For example, subclass the handler and add

    def send_response(self, code):
        super().send_response(code)
        if code == HTTPStatus.MOVED_PERMANENTLY:
            self.send_header("Content-Length", "0")

----------
components: Library (Lib)
messages: 392272
nosy: sirosen
priority: normal
severity: normal
status: open
title: Simple HTTP Request Handler in http.server does not set a content-length 
and does not close connections on 301s
versions: Python 3.6, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue43972>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to