in reply to Re^2: Question: how to check remote image property
in thread Question: how to check remote image property
Can't do it with LWP::Simple (natch), but yes if you use $ua->get( $url, :content_cb => ... ) you can pass a callback which dies after the requisite number of bytes have been received.
#!/opt/local/bin/perl use strict; use LWP::UserAgent (); my $ua = LWP::UserAgent->new(); $ua->env_proxy; my $rcvd = 0; my $buf = ''; my $resp = $ua->get( 'http://www.google.com/', ':content_cb' => sub { $buf .= $_[0]; die "NO MOR +\n" if ( $rcvd += length $_[0] ) > 512; }); print "content:\n", $buf, "\n\n"; print "headers:\n", $resp->as_string, "\n"; exit 0; __END__
If the callback gets too much your response object will have an X-Died header (if you care if it did or not).
The cake is a lie.
The cake is a lie.
The cake is a lie.
|
|---|