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

Hi, I am trying to migrate the following mod perl 1 code to mod perl 2 for a range request:

$r->headers_out->set('Accept-Ranges' => 'bytes'); my $range_request = $r->set_byterange; unless ((my $status = $r->meets_conditions) == OK) { return $status; } if ($range_request) { while( my($offset, $length) = $r->each_byterange) { seek $fh, $offset, 0; $r->send_fd($fh, $length); #TO DO: migrate to mod2 }

Reading up the documentation for mod perl 2: The functions $r->set_byterange and $r->each_byterange aren't in the Apache 2.0 API, and therefore don't exist in mod_perl 2.0. The byterange serving functionality is now implemented in the ap_byterange_filter, which is a part of the core http module, meaning that it's automatically taking care of serving the requested ranges off the normal complete response. There is no need to configure it. It's executed only if the appropriate request headers are set. These headers aren't listed here, since there are several combinations of them, including the older ones which are still supported. For a complete info on these see modules/http/http_protocol.c. sendfile accepts the following arguments: $filename $offset $length Is there a sequence of headers I am suppose to send out for it to interpret it as 206 partial download request? Thanks a bunch for any replies!

Replies are listed 'Best First'.
Re: mod2 equivalence for ($r->set_byterange and each_byterange)
by Anonymous Monk on Mar 17, 2011 at 19:11 UTC
    Is there a sequence of headers I am suppose to send out for it to interpret it as 206 partial download request? Thanks a bunch for any replies!

    Um, clients make request, so, it? Who? What?

      I am trying to make a partial content request(206) instead of a 200 request. I set the accepted ranges header but when I do a sendfile($fh) it does a 200 request instead of 206 request. So i was wondering if I am sending the correct headers for it to do a 206 request. thanks!
        I am trying to make a partial content request(206) instead of a 200 request.

        Um, clients make requests, servers make responses, part of which are response status codes, clients receive responses

        You say ap_byterange_filter is taking care of serving the requested ranges, without your program having to do anything special; if that is the case, then ap_byterange_filter is also responsible for turning the default 200 code your program sends into a 206 ; if ap_byterange_filter is taking care of things for you, your program doesn't have to do anything special