You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by eps com estem <gg...@mixmail.com> on 2005/10/18 22:27:15 UTC

bucketbrigades with html filter

I'm just changing my old "handler:FilterRequestHandler" in PerlOutputFilterHandler as it
is not working with my "new&fresh"mp2 compilation.

Then there's the question. What i want is to parse html pageswith an output filter that
take special tags (<%special%>)and insert there some specific content.

I've tried to do it by bucket brigades instead of the streaming-oriented solution. Once it
is done (following examples in docs) i ask myselfwhat will happens with a bucket with
"<%spe" and the next bucket with "cial%>".
I anticipate that the filter will not insert special content in that case.

I read something about underrun filters, but if i'm not wrong it is streaming-oriented.
Is it the only way to do it? Any opinion? Any doc?

Thanks!
---------------------------------------------------------
Juega y ll�vate una PS2 two: http://juegos.ya.com/consolas_y_pc/2005/09/concurso-ps2.html
Ya.com ADSL 2MB + Llamadas 24 horas: desde 26,95 �/mes + IVA. Navega y habla de forma ilimitada. Sin compromiso de permanencia. http://acceso.ya.com/ADSLllamadas/2mb

Re: bucketbrigades with html filter

Posted by Jeff Ambrosino <jb...@gmail.com>.
Yikes indeed :)

I should have clarified that in our app we don't actually process
embedded tags.  Our app lets users mangle the source HTML using RegEx,
and since users can (and often do) perform filtering like
s/(<body>)(.*?)(<\/body>)/$1<center>$2<\/center>$3/, we need to buffer
it all.

The main benefit I see in the Apache::Clean approach is that it's less
memory intensive for large content/pages...  and of course it's very
good as an example of how to manipulate content from within a filter. 
Aside from that, you're "cleaning" many times on smaller bits of
content vs. once if you buffer the entire page.  I'm curious where you
think the performance tradeoffs are for once-vs-many when the average
page size of 65kb.  In my specific case, even if we could operate on
chunks, I wager that there's more overhead in running many regexes vs.
one big one.  And I suppose one has to take into account the
per-invocation buffer size (1kb in Apache::Clean) as well as typical
bucket sizes... (8000 bytes?)

JB


On 10/18/05, Geoffrey Young <ge...@modperlcookbook.org> wrote:
> > The way to deal with this is to buffer as much content as you need
> > (maybe the whole page) and then do your work on the buffer.
>
> yikes!
>
> right.  see
>
>   http://search.cpan.org/~geoff/Apache-Clean-2.00_7/

Re: bucketbrigades with html filter

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Jeff Ambrosino wrote:
> The way to deal with this is to buffer as much content as you need
> (maybe the whole page) and then do your work on the buffer.

yikes!

>  Our
> application (HTTP output filter) buffers the stream as we go and
> stores it on the filter context ($f->ctx) across filter invocations. 
> When we've seen $f->eos, then we do our actual manipulations on the
> buffer, and we're done. 

right.  see

  http://search.cpan.org/~geoff/Apache-Clean-2.00_7/

for an example of this using the streaming API.

--Geoff

Re: bucketbrigades with html filter

Posted by Jeff Ambrosino <jb...@gmail.com>.
The way to deal with this is to buffer as much content as you need
(maybe the whole page) and then do your work on the buffer.  Our
application (HTTP output filter) buffers the stream as we go and
stores it on the filter context ($f->ctx) across filter invocations. 
When we've seen $f->eos, then we do our actual manipulations on the
buffer, and we're done.  Depending on how soon you know you're done,
you can even unhook your filter with $f->remove and let Apache send
the rest of the output straight through.

JB


On 10/18/05, eps com estem <gg...@mixmail.com> wrote:
[...]
> i ask myselfwhat will happens with a bucket with
> "<%spe" and the next bucket with "cial%>".
> I anticipate that the filter will not insert special content in that case.
[...]