You can use HTTPResponse::getContentLength()
or getContentLength64()
:
Returns the content length for this message, which may be UNKNOWN_CONTENT_LENGTH if no Content-Length header is present.
Note, that you have to call HTTPClientSession::receiveResponse()
first to receive the headers. You may also want to check HTTPResponse::getStatus()
to verify that the request was ok and HTTPResponse::getContentType()
if you're expecting a specific type.
For PDFs you can check the begin/end markers of the file itself. A proper PDF file should begin with %PDF-X.Y%
(where X.Y represents the version) and end with %%EOF
possibly followed by a 0x0D and/or 0x0A. A PDF file may contain multiple %%EOF
markers.