The HTTPServer class seems to have issues with pre-HTTP 1.0 type requests. The request is not passed to the GET handler until the client closes the connection.
Maybe the BaseHTTPRequestHandler tries to read non-existent headers or wants an empty line in the request?
Sending GET /foo\r\n and not closing connection afterwards should work.
I'm not sure whether you meant the connection on the client or the server, but note that it's possible to see a hang if you use echo. For instance echo "GET /index.html\r\n"| nc 127.0.0.1 8080 would make it hang but not with echo -e "GET /index.html\r\n" | nc 127.0.0.1 8080 and that's because the client request is not completed
The connection is terminated after the response has been sent.
But it is not terminated. The server hangs (probably misreading the request) until the client aborts the connection, then the request is finally processed but obviously there is nowhere to send the response.
changed the title [-]HttpServer hangs on HTTP 0.9 requests[/-][+]`BaseHTTPRequestHandler` incorrectly expects headers from HTTP/0.9 requests[/+]on Oct 2, 2025
Activity
picnixz commented on Oct 2, 2025
Can you show the server and client code? We need a reproducer to understand your issue.
Carmina16 commented on Oct 2, 2025
picnixz commented on Oct 2, 2025
What is the request you are sending? Make sure that request is a well-formed HTTP/0.9 as well
Carmina16 commented on Oct 2, 2025
Sending GET /foo\r\n and not closing connection afterwards should work.
picnixz commented on Oct 2, 2025
HTTP/0.9 is a one-line protocol. The connection is terminated after the response has been sent. See https://www.w3.org/Protocols/HTTP/AsImplemented. So it's working as intended.
picnixz commented on Oct 2, 2025
Btw, if you need to keep alive your connection, you need to use HTTP/1.1.
picnixz commented on Oct 2, 2025
I'm not sure whether you meant the connection on the client or the server, but note that it's possible to see a hang if you use echo. For instance echo "GET /index.html\r\n"| nc 127.0.0.1 8080 would make it hang but not with echo -e "GET /index.html\r\n" | nc 127.0.0.1 8080 and that's because the client request is not completed
Carmina16 commented on Oct 2, 2025
But it is not terminated. The server hangs (probably misreading the request) until the client aborts the connection, then the request is finally processed but obviously there is nowhere to send the response.
picnixz commented on Oct 2, 2025
Ah! I see what you mean. Sorry for misunderstanding the issue. Indeed, it's stuck in http.client.parse_headers.
picnixz commented on Oct 2, 2025
Actually this is a duplicate of #70765. I'll just attach that issue instead.