andreiashu has asked for the wisdom of the Perl Monks concerning the following question:

I'm using WWW::Mechanize to check if some files exist on a webserver.
I don't want to download the whole file, only some 10KB of it
I cannot use $mech->max_size because i think the server does not support the range header and thus responds with a "403 Forbidden".
So here is the code I try to run:
my $mech = new WWW::Mechanize( max_redirect => 20, autocheck => 1, onerror => \&onFetchError, onwarn => \&onFetchWarn ); # i cannot use max_size because i get a 403 # $mech->max_size("10240"); # so here is what i came up with: $mech->get($myUrl,":content_cb"=> \&myCallback); sub myCallback{ my ($data, $response, $protocol) = @_; my $totalData .= $data; if( (length($totalData ) / 1024) > 10 ){ #I want to stop the transfer now #but it's not working this way... $mech = undef; } }
Do you have any ideea how can i do this ? Or maybe other better solutions ?
Thanks

Replies are listed 'Best First'.
Re: Partial http file download
by rhesa (Vicar) on Feb 25, 2008 at 11:00 UTC
    Can't you do a HEAD request instead? If the file exists, you should receive useful information in the response header (such as content-type and content-length). If it doesn't exist, you should receive a 404.
      Thanks a lot !
      It worked nice this way :)
Re: Partial http file download
by Anonymous Monk on Feb 25, 2008 at 13:47 UTC
    you have to die