Remaining size should be checked at the end of the loop, the current implementation hang when POST request Content-Lenght is 0. We want to check for Content-Length header only if we received full header.