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

Hi all, I am trying to partially download a PDF with the following mod perl 2 code but I keep on getting a 200 response rather than a 206 response.

sub send{ my ($r) = @_; my $file = "/tmp/out.pdf"; my $file_size = = -s $file; my $attach_name = basename($file); $r->headers_out->set('Accept-Ranges' => 'bytes'); $r->headers_out->set('Content-Disposition' => "inline; filename=\"$a +ttach_name\""); $r->set_content_length($file_size); $r->content_type('application/pdf'); unless ((my $status = $r->meets_conditions) == OK) { return $status; } $r->sendfile($file); return OK; }

If the "Accept Ranges" is present doesn't Apache 2 send the proper headers so that the download is a partial download? Thanks a bunch for any replies!!

Replies are listed 'Best First'.
Re: partial content download in mod perl 2
by wind (Priest) on Mar 22, 2011 at 05:00 UTC
    It looks like you're just trying to serve the pdf.
    $r->content_type('application/pdf'); my $output = do { open my $pdf, $file or die "$file: $!"; binmode $pdf; local $/; <$pdf> }; # Return the page $r->header_out( 'Content-Length' => length($output) ); $r->send_http_header; $r->print($output); return OK;

      I have no problems serving the PDF but I want the code to be in mod perl 2 since we are now using Apache 2. Thanks for responding..