elnormous/HTTPRequest

A 204 response results in timeouts if connection is kept-alive...

Opened this issue · 0 comments

Hi,

I've noticed that a response with status 204 to, e.g., a POST request always results in a timeout if the connection is kept alive. RFC9110 specifies in 8.6 (https://www.rfc-editor.org/rfc/rfc9110.html#name-content-length) that A server MUST NOT send a Content-Length header field in any response with a status code of 1xx (Informational) or 204 (No Content).

It seems that the library is still trying to parse the body of a 204 response. But since the header of such a response does not contain a Content-Length field, contentLengthReceived stays false and the library tries to receive more data via the socket. If the server closes the connection, we won't receive any more data from the socket and the function returns the response. But if the connection is kept-alive, the socket.recv()-call will timeout as the server is not sending any more data but the socket is still open.