If the server provides a header field Content-Length, then this is easy. If this is not the case, you are out of luck.
Reasonable server implementations provide Content-Lengthwhen the content is static and has a known size. If the content is dynamically generated, it is impossible to know the length a priori, at least without making two passes through the data.