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 Nick Kew <ni...@apache.org> on 2009/08/16 02:08:59 UTC

[Fwd: Re: Having some issues with subrequests and filters]

Michael Spiegle wrote:
> Hello,
> I have a module I am writing which implements a content-generator and
> a filter.  If I make a sub-request from within my content-generator,
> the filter's (request_rec*)f->r only points to the original request.
> How do I access the current sub-request from within my filter?

How do you know the subrequest exists at the point where you access
it from the filter?

Put whatever you need on your module's filter's context.

-- 
Nick Kew

Re: [Fwd: Re: Having some issues with subrequests and filters]

Posted by Michael Spiegle <mi...@nauticaltech.com>.
On Tue, 18 Aug 2009 13:56:51 +0200, Sorin Manolache <so...@gmail.com>
wrote:
> On Tue, Aug 18, 2009 at 08:38, Michael Spiegle<mi...@nauticaltech.com>
> wrote:
>> Nick Kew wrote:
>>>
>>> Michael Spiegle wrote:
>>>>
>>>> Hello,
>>>> I have a module I am writing which implements a content-generator and
>>>> a filter.  If I make a sub-request from within my content-generator,
>>>> the filter's (request_rec*)f->r only points to the original request.
>>>> How do I access the current sub-request from within my filter?
>>>
>>> How do you know the subrequest exists at the point where you access
>>> it from the filter?
>>>
>>> Put whatever you need on your module's filter's context.
>>>
>>
>>
>> I was hoping that when my filter starts receiving data for a subrequest,
>> the
>> request_rec* attached to the filter would indicate that it was a
>> subrequest
>> via f->r->main not being NULL.  It seems like you can use that logic
>> everywhere else, so why not in the filter context?
>>
> 
> I use the following code:
> 
> request_rec *newreq = ap_sub_req_lookup_uri(url, req, NULL);
> ap_filter_t *flt = ap_add_output_filter(FILTER_NAME, NULL, newreq,
> newreq->connection);
> // flt->ctx = &flt_ctx;
> int ret_code = ap_run_sub_req(newreq);
> ap_destroy_sub_req(newreq);
> 
> The filter is
> 
> apr_status_t output_filter(ap_filter_t *f, apr_bucket_brigade *bb) {
>  // f->r->main is not NULL !
> }
> 
> This code works for me.
> 
> I hope this helps.
> 
> S

Wow, I feel like an idiot.  I had the same thing you just posted except my
ap_add_ouput_filter() function used the old request instead of 'newreq'. 
This fix seems to have solved my issue.  Thank you very much!

-- 
Michael Spiegle

Re: [Fwd: Re: Having some issues with subrequests and filters]

Posted by Sorin Manolache <so...@gmail.com>.
On Tue, Aug 18, 2009 at 08:38, Michael Spiegle<mi...@nauticaltech.com> wrote:
> Nick Kew wrote:
>>
>> Michael Spiegle wrote:
>>>
>>> Hello,
>>> I have a module I am writing which implements a content-generator and
>>> a filter.  If I make a sub-request from within my content-generator,
>>> the filter's (request_rec*)f->r only points to the original request.
>>> How do I access the current sub-request from within my filter?
>>
>> How do you know the subrequest exists at the point where you access
>> it from the filter?
>>
>> Put whatever you need on your module's filter's context.
>>
>
>
> I was hoping that when my filter starts receiving data for a subrequest, the
> request_rec* attached to the filter would indicate that it was a subrequest
> via f->r->main not being NULL.  It seems like you can use that logic
> everywhere else, so why not in the filter context?
>

I use the following code:

request_rec *newreq = ap_sub_req_lookup_uri(url, req, NULL);
ap_filter_t *flt = ap_add_output_filter(FILTER_NAME, NULL, newreq,
newreq->connection);
// flt->ctx = &flt_ctx;
int ret_code = ap_run_sub_req(newreq);
ap_destroy_sub_req(newreq);

The filter is

apr_status_t output_filter(ap_filter_t *f, apr_bucket_brigade *bb) {
 // f->r->main is not NULL !
}

This code works for me.

I hope this helps.

S

-- 
A: Because it reverses the logical flow of conversation.
Q: Why is top-posting frowned upon?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

Re: [Fwd: Re: Having some issues with subrequests and filters]

Posted by Michael Spiegle <mi...@nauticaltech.com>.
Nick Kew wrote:
> Michael Spiegle wrote:
>> Hello,
>> I have a module I am writing which implements a content-generator and
>> a filter.  If I make a sub-request from within my content-generator,
>> the filter's (request_rec*)f->r only points to the original request.
>> How do I access the current sub-request from within my filter?
>
> How do you know the subrequest exists at the point where you access
> it from the filter?
>
> Put whatever you need on your module's filter's context.
>


I was hoping that when my filter starts receiving data for a subrequest, 
the request_rec* attached to the filter would indicate that it was a 
subrequest via f->r->main not being NULL.  It seems like you can use 
that logic everywhere else, so why not in the filter context?