Apache-File-Resumable
view release on metacpan or search on metacpan
Resumable.pm view on Meta::CPAN
my $range = $req->header_in('Range') ;
my $if_range = $req->header_in('If-Range') ;
### If there is a correct range header and the if-range header matches
### the etag
### i.e. the file doesn't have changed, add the correct headers for
### resuming the
### download and advance the file pointer to the correct possition
if (($range =~ /bytes=(\d+)-/) && $if_range eq $etag)
{ # continue download
my $start = $1 ;
my $end = $size - 1 ;
$req->status (206) ;
$req->header_out('Content-Range', "bytes $start-$end/$size" ) ;
$size -= $start ;
seek PATCH, $start, 0 ;
}
### To make resuming a download work, we need _all_ of the follwing
### headers!
$req->header_out('Accept-Ranges', 'bytes');
$req->header_out('Last-Modified', formattime ($mtime)) ;
$req->header_out('Content-Length', $size) ;
### Setup the content-type
if ($file =~ /\.zip$/i) {
$req->content_type('application/zip');
}
elsif ($file =~ /\.Z$/i) {
$req->content_type('Content-type: application/compress');
}
else {
$req->content_type('application/octet-stream');
}
### Send the headers
$req->send_http_header ;
### ... and now send the content
no strict 'subs';
$req->send_fd(PATCH);
close PATCH;
return OK ;
}
sub doit {
my $r = shift ;
download ({}, '/home/httpd/html/old.zip', $r) ;
#download ({}, '/home/httpd/html/c.zip', $r) ;
}
#doit;
1;
__END__
# Below is stub documentation for your module. You better edit it!
=head1 NAME
Apache::File::Resumable - example of how to serve resumable files under modperl
=head1 SYNOPSIS
This code can be adapted to serve resumable downloads under mod_perl.
As it is setup now, you could put this file in some directory under your
document root with a name like /home/httpd/htdocs/bigfile.afr (that's
right, name an executable Perl file with this extension), then setup
Apache to run files with that extension as a script:
<Files *.afr>
however that is done
</Files>
Then uncomment the line
#doit
in the same file and it will serve the zip file indicated in the
subroutine download(), in a resumeable fashion.
I'm sorry for not giving you a complete handholding on this, but I
feel that this code is close enough to be of great service to some
that I think that you should just go the extra few more yards to the
goal-line to finish it off. And email me the fixes to the docs when
you do.
I have used this code to get resumable downloads working, I just
forgot
the Apache settings to do it.
=head1 DESCRIPTION
=head2 EXPORT
None by default.
=head1 AUTHOR
T. M. Brannon, <tbone@cpan.org>
=cut
( run in 0.564 second using v1.01-cache-2.11-cpan-13bb782fe5a )