You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Michael Spiegle <mi...@nauticaltech.com> on 2010/01/12 04:48:24 UTC

Filtering subrequest through byterange filter?

I have a module that oftentimes needs to use a subrequest in order to
finish sending the response.

If I create the subrequest via ap_sub_req_lookup_uri(), then add a
"Range" header to sr->headers_in, this appears to work ok if my
subrequest is destined for mod_proxy.  I believe this is because
mod_proxy just passes all the headers through, and the backend server is
actually doing the byterange work for me.

If I have the same situation, but the subrequest is being serviced by a
local file, the byterange filter won't run even if I explicitly add it
in the chain via ap_add_output_filter().  As far as I can tell, the
filter gets added to sr->proto_output_filters, but not
sr->output_filters like a normal request.  I'm assuming this is because
the response has already started, and thus the headers have already been
sent.

I understand that there could be certain situations where I can't rely
on the byterange filter, but I don't believe I would encounter them in
my application.  Is there any way to get this to work, or am I doing
something totally wrong?  Here's an example of the code I'm using:

//byte_range contains a valid bytes=X-Y value
request_rec* sub_request = ap_sub_req_lookup_uri(r->uri, r, NULL);
ap_add_output_filter("BYTERANGE", NULL,
                           sub_request, sub_request->connection);
apr_table_set(sub_request->headers_in, "Range", byte_range);
ap_run_sub_req(sub_request);

Thanks,
Mike

Re: Filtering subrequest through byterange filter?

Posted by Nick Kew <ni...@apache.org>.
On 12 Jan 2010, at 03:48, Michael Spiegle wrote:

> I have a module that oftentimes needs to use a subrequest in order to
> finish sending the response.
> 
> If I create the subrequest via ap_sub_req_lookup_uri(), then add a
> "Range" header to sr->headers_in, this appears to work ok if my
> subrequest is destined for mod_proxy.  I believe this is because
> mod_proxy just passes all the headers through, and the backend server is
> actually doing the byterange work for me.

Yep, makes sense.

> If I have the same situation, but the subrequest is being serviced by a
> local file, the byterange filter won't run even if I explicitly add it
> in the chain via ap_add_output_filter().

The subrequest isn't running its own private filter; it's feeding into the 
common filter chain, which sees the headers from the main request.

> I understand that there could be certain situations where I can't rely
> on the byterange filter, but I don't believe I would encounter them in
> my application.  Is there any way to get this to work, or am I doing
> something totally wrong?

Filters and subrequests are a difficult area, and I don't think there's
a "good" (non-hackish) way to do what you want (short of the proxy).
If you were to run a subrequest with its own private filter chain, you
have to figure out exactly where/how it feeds into the "main" request
filters.

I'll be interested if you do come up with a good solution that could
be incorporated into the API for others facing similar issues.

[this response is OTTOMH - I don't think I have anything more to
add than confirmation of what you've found - sorry].

-- 
Nick Kew