The HTTP server runs requests that are already in its receive buffer after it has queued a reply that closes the connection. RFC 9112 section 9.6 says it must not. This is a regression from #35182, which replaced libevent: libevent's evhttp_send_done() frees the connection once a closing reply is sent, so buffered requests were never parsed. The server also keeps the connection open after a request with both Content-Length and Transfer-Encoding. Section 6.1 says it must close it. Until both are fixed, a request sent right behind a request with both headers is run.
The first commit stops reading requests from a client once a closing reply is queued or the client is flagged for disconnection. Its code and unit tests are azuchi's work from #36355, which was closed. The second commit makes WriteReply() send "Connection: close" for a request with both headers, so the server closes the connection. It extends the Content-Length plus Transfer-Encoding case in interface_http.py: a setnetworkactive false request sent right behind it must not run, and the only reply must say "Connection: close". Tested with test_bitcoin --run_test=httpserver_tests and the functional tests interface_http.py, interface_rpc.py and interface_rest.py, which pass.