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 "Dennis J." <de...@conversis.de> on 2009/03/30 04:00:23 UTC

preventing filter from running for server side includes

Hi,
Im trying to develop a simple filter that adds a header and a footer to a 
page. My problem is that the page can also contain server side includes and 
I obviously only want to add the header and footer on the "outer" part of 
the document. If I don't allow server side includes things work out fine: 
In the filter I check if f->ctx is set. If it isn't I initialize it and 
push out the header. Then I pass through the response data and when I hit 
the EOS bucket I push out the footer. That works as it should.

Once I add the server side includes into the mix I thought I simply check 
f->r->main is this is a sub-request and don't output the header and footer 
and simply pass through the data. That actually seems to work too.

My problem is that according to the debug log output there is an additional 
sub-request happening and I don't really understand where that is coming from.

This is test.html:
<html>
<body>
test
<!--#include virtual="test2.html" -->
</body>
</html>

Simple enough. "test2.html" only contains the word "inc".

When I request "test.html" I get the following output in the debug log:

mod_mymodule: filter called (/test.html)
mod_mymodule: filter: init f->ctx (/test.html)
mod_mymodule: insert header (/test.html)
mod_mymodule: filter: regular bucket found (/test.html)
mod_mymodule: leaving filter (/test.html)

     mod_mymodule: filter called (/test2.html)
     mod_mymodule: filter: init f->ctx (/test2.html)
     mod_mymodule: skipping header (/test2.html)
     mod_mymodule: filter: regular bucket found (/test2.html)

         mod_mymodule: filter called (/test.html)
         mod_mymodule: filter: init f->ctx (/test.html)
         mod_mymodule: insert header (/test.html)
         mod_mymodule: filter: regular bucket found (/test.html)
         mod_mymodule: leaving filter (/test.html)

     mod_mymodule: filter: EOS bucket found (/test2.html)
     mod_mymodule: skipping footer (/test2.html)
     mod_mymodule: leaving filter (/test2.html)

mod_mymodule: filter called (/test.html)
mod_mymodule: filter: f->ctx already initialized
mod_mymodule: filter: regular bucket found (/test.html)
mod_mymodule: filter: EOS bucket found (/test.html)
mod_mymodule: insert footer (/test.html)
mod_mymodule: leaving filter (/test.html)

I indented the output to make the call structure more visible.

I get the first and second level and there everything seems to work out 
fine. Header and footer get inserted on level 1 and the are skipped for 
level 2 since it's a sub-request. But where does the third invocation of 
the filter for "test.html" come from?

Alternatively how can I make sure that header and footer are only output 
once for the overall request? Does anyone have an idea for a better strategy?

Regards,
   Dennis