filter priorities and order of execution

Alex Krohn <[email protected]>
Newsgroups gmane.comp.apache.mod-perl
Message-ID <[email protected]>
Hi,

I'm still looking at getting range requests working properly with
mod_perl:

    http://www.gossamer-threads.com/lists/modperl/dev/104360

and have decided to go with an output filter to set the eos bucket. 

Can anyone help with how order execution works? I have a simple conf
like:

    PerlRequire /home/alex/modperl.pl
    <Location /perl/>
        SetHandler modperl
        PerlResponseHandler VideoTest
        PerlOutputFilterHandler VideoTest::test_output_handler
    </Location>

and my modperl code looks like:

    sub handler {
        my $r = shift;
        $r->sendfile('/tmp/video.mp4');
        $r->pnotes("send_eos" => 1);
        $r->add_output_filter(\&test_add_output_filter);
        return Apache2::Const::OK;
    }

    sub test_add_output_filter {
        # transparent filter
        my ($f, $bb) = @_;
        warn "in add_output_filter";
        my $rv = $f->next->pass_brigade($bb);
        return $rv unless $rv == APR::Const::SUCCESS;
        warn "leaving add_output_filter";
        return Apache2::Const::OK;
    }

    sub test_output_handler {
        # sets eos depending pnotes
        my ($f, $bb) = @_;
        warn "in test_output_handler";
        my $r = $f->r;
        if ($r->pnotes("send_eos")) {
            warn "adding eos";
            my $ba = $bb->bucket_alloc;
            my $b = APR::Bucket::eos_create($ba);
            $bb->insert_tail($b);
        }
        else {
            warn "skipping eos modifications";
        }
        my $rv = $f->next->pass_brigade($bb);
        return $rv unless $rv == APR::Const::SUCCESS;

        warn "leaving test_output_handler";

        return Apache2::Const::OK;
    }

and the debug looks like:

    in test_output_handler at /home/alex/modperl.pl line 31.
    skipping eos modifications at /home/alex/modperl.pl line 40.
    [Tue May 29 09:05:20 2012] [debug] byterange_filter.c(256): [client 127.0.0.1] found unknown length: clength = 125569
    leaving test_output_handler at /home/alex/modperl.pl line 46.
    in test_output_handler at /home/alex/modperl.pl line 31.
    adding eos at /home/alex/modperl.pl line 34.
    in add_output_filter at /home/alex/modperl.pl line 21.
    leaving add_output_filter at /home/alex/modperl.pl line 24.
    leaving test_output_handler at /home/alex/modperl.pl line 46.

I know I have add_output_filter and perloutputfilterhandler, just trying
to see which option runs when (as ideally add_output_filter would work
best). 

So my questions are:

1. Why does test_output_handler set by PerlOutputFilterHandler get
called twice?

2. Why does the first time called not know about pnotes, but the second
time it does?

3. Why does add_output_filter happen at the end, and is there a way to
have it happen at same position as perloutputfilterhandler?

Basically, in order for range requests to work, I need to set the eos
bucket before byterange_filter is called. If it happens after that, it's
too late and range requests won't work.

Any help is really appreciated, been struggling here for quite some time.
=)

Thanks!

Alex
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.