Sounds easy right? Almost. There is, unfortunately, a bit more to it than to just search for a CRLF-String or testing whether the content-length matches. Just for the curious, this is a list of valid response-finished detection techniques.

1. Content-Length
If the response has a content-length-header, it's easy. Just check whether the body of the response is already as long as the content-length-field specifies and the response is finished once the values match.

2. Non-Identity Transfer-Coding
A transfer encoding is great for when the server does not specify a content-length ( which he must not if the server uses a non-identity transfer coding anyway ). Chunked encoding is a transfer encoding ( unlike gzip, which is a content-encoding ) and splits the body into chunks. The chunked encoding has a well-defined end, once you find that in your data, the response is complete.

3. Connection: Close
Neither Content-Length nor Transfer-Coding anywhere? Just hope for the remote server to close the connection at some point. If this happens and the server specifies a connection: close header ( or it's a HTTP/1.0 conversation, which uses close implicitly if nothing else is specified ), the response is complete.

4. If nothing of the above happens, just hope that the remote server closes the connection, which is about the only way you can be certain that the connection ended.

HTTP is a mess.