HTTP specification (RFC2616) has the following phrase:
If a Transfer-Encoding header field (section 14.41) is present and
has any value other than “identity”, then the transfer-length is
defined by use of the “chunked” transfer-coding (section 3.6),
unless the message is terminated by closing the connection.
How can I detect that the message is “terminated by closing the connection”? Is it enough to check the “Connection” field for value “close”?
I think that the RFC points to the TCP connection, when you read 0 bytes from the socket, the other side has closed the connection.
More:
Can read() function on a connected socket return zero bytes?