Re: Two questions regarding LWP

Byron Brummer (byron@omix.com)
Wed, 13 Oct 1999 14:45:57 +0000 (GMT)


KS <ksiero@sgh.waw.pl> wrote:
> 1) I would like to determine the size of the file without really downloading it.
> Is it possible , maybe some HEAD request would be approperiate. How do I do it?

    use LWP::UserAgent;
    use HTTP::Request;
    
    my $ua = LWP::UserAgent->new()->request(
        HTTP::Request->new(
            HEAD => "http://someplace.com/"
        )
    );
    if ($ua->is_success) {
        print $ua->headers()->content_length()
    }

> 2) Can I stop getting the file when I reache certain limit , like after
> first 15kb that are of my interest ?

    use LWP::UserAgent;
    use HTTP::Request;

    my $req = HTTP::Request->new(
        GET    => "http://localhost/"
    );
    $req->header( Range => "bytes=0-15360" );
    my $ua = LWP::UserAgent->new()->request($req);
    if ($ua->is_success) {
        print $ua->content();
    }

    # HTH

-- 
-Zenin (zenin@archive.rhps.org)           From The Blue Camel we learn:
BSD:  A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts.  Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.)  The full chemical name is "Berkeley Standard Distribution".