in reply to Re: Determining Content-Length when there is no Content-Length header
in thread Determining Content-Length when there is no Content-Length header

OK, this is a very old thread, but I looked at this thread when searching for some information on a related problem, and now that I've solved it I think it should be posted here since Googling "Perl CURLOPT_RANGE" doesn't currently return any useful hits.

OK, the bottom line is that if you want to fetch a piece of a remote file using Perl you can take the WWW:Curl package

http://search.cpan.org/~szbalint/WWW-Curl-4.15/lib/WWW/Curl.pm

and modify the first example to include the lines

my $firstbyte = 50; my $lastbyte = 100; $curl->setopt(CURLOPT_RANGE,"$firstbyte-$lastbyte");

So the OP could use this technique to see whether, e.g. he's able to successfully fetch the 1,000,000th byte of a remote file. If he can fetch it, then he might decide not to try to download that file.

I hope that this info is useful to someone.

  • Comment on Re^2: Determining Content-Length when there is no Content-Length header
  • Download Code

Replies are listed 'Best First'.
Re^3: Determining Content-Length when there is no Content-Length header
by afoken (Chancellor) on Apr 14, 2011 at 16:47 UTC

    Nice idea, but not all web servers / web applications support byte ranges. I think the proper behaviour for a web server is to ignore the unknown / unsupported header and send the entire resource -- which is clearly not what the OP wanted. See also Re: Determining Content-Length when there is no Content-Length header

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)