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 Sven Kägi <Sv...@trivadis.com> on 2007/10/09 13:46:42 UTC

Filter function is called three times

Hi all,

I'm just trying to write my first Module (actually a filter) for Apache and
made an observation I can't explain.

I have now made an empty skeleton that has some dummy configuration and
a callback function for my filter that I registered as follows:

static void register_hooks(apr_pool_t *p)
{
  ap_register_input_filter(tvdldapfilter_name, insert_ldap_headers, NULL,
                           AP_FTYPE_CONTENT_SET);
}

The callback function itself has at the moment no functionality apart from
reading the dummy config and some logging.

I compiled the whole stuff, tested it with apache and it works fine. The only
thing is: according to my logs my filter is called three times (twice with
mode == AP_MODE_READBYTES and once with some other mode). The test page I call
is a simple html-Page with no pictures or additional stuff. Actually it's a
copy from the "It-Works!"-page.

Finally my question: What could be the reason why my filter is called three
times instead of once and is there something I could do about that?

Thanks for any hint
Sven

Re: AW: Filter function is called three times

Posted by Joe Lewis <jo...@joe-lewis.com>.
Sven Kägi wrote:
> Hi again,
>
> Thanks for your hints.
>
>   
>> If the request is for a directory, you may see three separate requests,
>> each one ending in the DirectoryIndex options (e.g. /dir/index.html
>> /dir/index.htm, /dir/index.cgi, etc).  These are typically subrequests
>> that a single request generates if the request doesn't match a file
>> directly.
>>     
>
> I tried that out by typing in <myurl>/filtered/index.html to match
> the file directly (besides this stuff is configured as <Location> and
> not as <Directory>) with the same results I had when I typed <myurl>/filtered/.
>
>   
>> For fully understanding these, try logging the request URI.
>>     
> The request-URI is always /filtered/index.html.
>
> Interestingly its even the same if I type in an error.
> My logs then say that first my input filter is called exactly once.
> Then the content-handler is called saying "File does not exist" and then
> again my filter is called twice more as in the sample before.
>   

Again, just log the r->uri to see what it is getting called on in your
input filter.  You may find an /error/404_NOT_FOUND.html reference,
which will actually be a sub request due to a missing document. 
Referencing the file directly should have shown us the file, however, if
we are missing an alias, or if we aren't mapping directly to a file that
apache knows of, we'll get the 404_NOT_FOUND errors.

>   
>> It could also be related to a browsers ability to request just the
>> headers (via HEAD) or a full document (via GET) for caching.
>>     
> I think I should see that in the access file. Right?
> In the access file I only see one GET - request.
>   

Absolutely.  It should show in the access log.

>   
>> I'd suggest logging a few of the request_rec fields just to be sure.
>>     
> This I haven't tried until now. I'll try that out and see what I can figure out.
>
> Thanks for your help again.
>
> Sven
>   


-- 
Joseph Lewis <http://sharktooth.org/>
"Divide the fire, and you will sooner put it out." - Publius Syrus

AW: Filter function is called three times

Posted by Sven Kägi <Sv...@trivadis.com>.
Hi again,

Thanks for your hints.

>If the request is for a directory, you may see three separate requests,
>each one ending in the DirectoryIndex options (e.g. /dir/index.html
>/dir/index.htm, /dir/index.cgi, etc).  These are typically subrequests
>that a single request generates if the request doesn't match a file
>directly.

I tried that out by typing in <myurl>/filtered/index.html to match
the file directly (besides this stuff is configured as <Location> and
not as <Directory>) with the same results I had when I typed <myurl>/filtered/.

>For fully understanding these, try logging the request URI.
The request-URI is always /filtered/index.html.

Interestingly its even the same if I type in an error.
My logs then say that first my input filter is called exactly once.
Then the content-handler is called saying "File does not exist" and then
again my filter is called twice more as in the sample before.

>It could also be related to a browsers ability to request just the
>headers (via HEAD) or a full document (via GET) for caching.
I think I should see that in the access file. Right?
In the access file I only see one GET - request.

>I'd suggest logging a few of the request_rec fields just to be sure.
This I haven't tried until now. I'll try that out and see what I can figure out.

Thanks for your help again.

Sven

Re: Filter function is called three times

Posted by Joe Lewis <jo...@joe-lewis.com>.
Sven Kägi wrote:
> Hi all,
>
> I'm just trying to write my first Module (actually a filter) for Apache and
> made an observation I can't explain.
>
>   

[snip]

> I compiled the whole stuff, tested it with apache and it works fine. The only
> thing is: according to my logs my filter is called three times (twice with
> mode == AP_MODE_READBYTES and once with some other mode). The test page I call
> is a simple html-Page with no pictures or additional stuff. Actually it's a
> copy from the "It-Works!"-page.
>
> Finally my question: What could be the reason why my filter is called three
> times instead of once and is there something I could do about that?
>
> Thanks for any hint
> Sven
>   
If the request is for a directory, you may see three separate requests,
each one ending in the DirectoryIndex options (e.g. /dir/index.html
/dir/index.htm, /dir/index.cgi, etc).  These are typically subrequests
that a single request generates if the request doesn't match a file
directly.

For fully understanding these, try logging the request URI.

It could also be related to a browsers ability to request just the
headers (via HEAD) or a full document (via GET) for caching.

I'd suggest logging a few of the request_rec fields just to be sure.

Joe
-- 
Joseph Lewis <http://sharktooth.org/>
"Divide the fire, and you will sooner put it out." - Publius Syrus