PerlOutputFilterHandler runs twice...?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I've tried to set up an output filter to make my life esier in
developing a site. Rather than explicitly output SSI directives inside
the response handlers or registry scripts, I've made an output filter
like so:

package Local::GCPage;

use strict;
use warnings;

use base qw(Apache2::Filter);
use Apache2::Const -compile => qw(OK);
use constant BUFF_LEN => 1024;

sub handler : FilterRequestHandler {
    my $f = shift;

    $f->print('<!--#include virtual="/elements/top.shtml" -->');

    while ($f->read(my $buffer, BUFF_LEN)) {

    $f->print('<!--#include virtual="/elements/bottom.shtml" -->');

    return Apache2::Const::OK;

Now, the thing is... it's running twice.

I turned off PerlSetOutputFilter to try and make it easier to read
what was going on with a tiny registry script that just says "Test
worked?<br/>\n" and got this:

<!--#include virtual="/elements/top.shtml" -->Test worked?<br/>
<!--#include virtual="/elements/bottom.shtml" -->
<!--#include virtual="/elements/top.shtml" --><!--#include virtual="/
elements/bottom.shtml" -->

Notice the top and bottom SSI tags in there twice.

I have my httpd.conf set up like so to deal with these:

<Directory "/usr/local/gc">
    Options Indexes FollowSymLinks MultiViews Includes ExecCGI
    DirectoryIndex index.html index.shtml index.gc index.cgi index.php
    AllowOverride All
    Order allow,deny
    Allow from all
    AddHandler perl-script .gc
    PerlOptions +ParseHeaders +GlobalRequest +SetupEnv

    <Files ~ "\.gc">
        PerlFixupHandler Local::PrepSession
        PerlOutputFilterHandler Local::GCPage
        #PerlSetOutputFilter INCLUDES

I'm not understanding why I get the filter run twice, once on the
actual content and then again underneath everything wrapped around an
empty string. I could easily modify the thing to make sure it has
content to wrap around, but that seems like a crappy kludge. Something
must be configured wrong.

BTW I also tried it with a DECLINED return value. Same thing. No

Re: PerlOutputFilterHandler runs twice...?

Quoted text here. Click to load it

Actually, it's worse than that. I added, for temporary kludging, to
the filter to make it not print anything unless there's something to
filter (i.e. don't put atop and bottom tag around nothingness). It
appears it runs multiple times if the content is too long, though.

It seems like what I want to do should be really simple... just add an
SSI tag for a top of page, spit out the actual content, and an SSI tag
for a bottom of the page, then pass the whole lot on to normal SSI
filtering. Like so:



<#!--include virtual="top.shtml"-->
<#!--include virtual="bottom.shtml"-->

So why isn't it being simple? Why is it being a big pain in the butt?
Doesn't everyone want to do this at some point or another? (if not SSI
tags, then just anything before and after the content)

I figured out I could do the top part with a further kludge... using
the ctx() method to determine if it's already been output. That
doesn't help with the bottom tag.

Site Timeline