Re: a question for LWP: it seems that you can send a "GET"
Gisle Aas (gisle@aas.no)
30 Jul 1999 08:41:13 +0200
Kin Lum <kin@0011.com> writes:
> here is my question for LWP: it seems that you can send a "GET"
> request for a file, but say, starting at byte 5000
> and then you want just 2000 bytes.
>
> Is that possible?
You can use the 'Range' HTTP header. Not all servers/resources will
honor it, so you should not be too suprised if you get the whole thing
back. Something like this should do the trick:
use LWP;
$req = HTTP::Request->new(GET => "http://www.somewhere.com");
$req->header(Range => "bytes=5000-6999");
$res = LWP::UserAgent->new->request($req);
print $res->as_string;
If it works you get a response like this back:
HTTP/1.1 206 Partial Content
Connection: close
Date: Fri, 30 Jul 1999 06:31:59 GMT
Accept-Ranges: bytes
Server: Apache/1.3.0 (Unix)
Content-Length: 2000
Content-Range: bytes 5000-6999/15234
Content-Type: text/html
ETag: "34576756-2a2-358443f8"
Last-Modified: Sun, 14 Jun 1998 21:43:20 GMT
If differs from the normal response by a 206 status code instead of
the normal 200, and you should also see a Content-Range header.
> The routines I saw are all getting the complete file.
>
> And if it is possible, can most Web server support it?
Apache can.
> I think some cannot?
Probably. There are probably also a lot of server scripts that don't
look for the Range header either.
Regards,
Gisle