Stephen Rosen <[email protected]> added the comment:
Ach! Sorry! I didn't even realize this but the issue only arises when you are
modifying the handler to set the protocol to HTTP/1.1 .
In HTTP/1.0 , there's no notion of persistent connections, so the issue does
not arise.
But when the protocol version changes to 1.1 , persistent connections are the
norm, and curl will wait indefinitely.
The following short script is sufficient to reproduce:
```
import http.server
class CustomRequestHandler(http.server.SimpleHTTPRequestHandler):
protocol_version = "HTTP/1.1"
with http.server.HTTPServer(("", 8000), CustomRequestHandler) as httpd:
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\nKeyboard interrupt received, exiting.")
```
After double-checking the docs, the current doc for `protocol_version` [1] is
quite clear about this:
"your server must then include an accurate Content-Length header (using
send_header()) in all of its responses to clients"
I still think the fix I proposed is an improvement. Setting a Content-Length
isn't forbidden in HTTP/1.0 , and it guarantees good behavior when HTTP/1.1 is
used.
[1]
https://docs.python.org/3/library/http.server.html#http.server.BaseHTTPRequestHandler.protocol_version
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue43972>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com