get the file size of a CFHTTPStream

592 views Asked by At

How to get a file size of a CFHTTPStream. Suppose a file called "http://testserver.com/test.jpg " is available to read. Here I need to get the file size "test.jpg", this I need to display progress while using CFReadStreamRead.

Or in other words I need how many bytes are available in the server
before the start of the read process.

Thanks in advance

Mohsin

1

There are 1 answers

0
Leland Wallace On

You would get the message header from the stream thusly:

CFHTTPMessageRef message = CFReadStreamCopyProperty(requestStream, kCFStreamPropertyHTTPResponseHeader);

And then copy out the header fields:

CFDictionaryRef headerFields = CFHTTPMessageCopyAllHeaderFields(message);

and then grab the content-length field from the dictionary.

I don't completely remember the specific field name so dump the dict & grab the one which looks right. You will need to read at least a little bit of the stream to get the header.