On Jul 8, 3:12 pm, Travis D Warlick Jr email@example.com
len = response[‘Content-Length’].to_i
- Travis D Warlick, Jr
- Lead Developer
- Operis Systems, LLC
Check the HTTP protocol spec (RFC - Google for it) to find out whether
servers are required to send the Content-Length header - just to know.
But that won’t help you, of course, for those servers that don’t do it
anyway, even if required by the spec
This workaround is not tested, but you could try it:
According the the HTTP spec, IIRC, the end of HTTP headers is
indicated by two consecutive ‘\r\n’ pairs, i.e. ‘\r\n\r\n’.
So (if open-uri always pulls the whole file, as Robert K. says_,
look in the Ruby docs for a read() method in some suitable Net class
(maybe open-uri or Net:Http), to enable you to read the file by byres
- write your code to look for the end of header indicator, and just
stop reading after that. Then parse the headers you read, for the
Content-Length field, to get the file size.
Also try using HEAD instead of GET. If the server implements it
correctly, it should only send the HTTP headers in this case.