You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Torsten Foertsch <to...@gmx.net> on 2008/04/18 10:35:02 UTC

Re: filter->remove

On Thu 17 Apr 2008, woinshet abdella wrote:
> I am sorry to write you directly, but did not get any response from the
> modperl user list. I would appreciate you help in advance!

Please ask on the modperl list in the future. If you don't get an answer try 
it again. We all are sometimes too busy to answer questions on the list. So 
be patient, polite but insistent.

> Last time you send me the following code. I tried it for the last serveral
> days but I did not succeed, it is not REMOVING the filter from the chain
>
> unless($f->ctx ) {
>   unless( $f->r->headers_in->{'User-Agent'} eq 'Wanted' ) {
>     $f->remove;
>     return Apache2::Const::DECLINED;
>   }
> }
>
> Environment:
>
> Red Hat Enterprise Linux
> Apache/2.0.46
> perl, v5.8.0

Those are quite old. If your mod_perl is that old as well that may be the 
reason. I have attached 2 very simple modules that I have used for some time. 
Apache2::PrintFilterChain prints the current output filter chain to the 
error_log. Apache2::Remove... removes the next filter in the chain if the 
content type of the document being delivered is not text/html. Both modules 
remove themselves on the first invocation. Hence they are called only once 
per document.

PerlOutputFilterHandler Apache2::PrintFilterChain
PerlOutputFilterHandler Apache2::RemoveNextFilterIfNotTextHtml
PerlSetOutputFilter INCLUDES
PerlOutputFilterHandler Apache2::PrintFilterChain

If used on a HTML document you should see in the output of the first 
invocation of PrintFilterChain 2 times PrintFilterChain, once the filter 
removing filter and once INCLUDES. The second PrintFilterChain will show 
INCLUDES and one PrintFilterChain:

Here an output example for text/plain:

Filter Chain:
  modperl_request_output           <-- the first PrintFilterChain
  modperl_request_output           <-- RemoveNextFilterIfNotTextHtml
  includes
  modperl_request_output           <-- PrintFilterChain again
  byterange
  content_length
  http_header
  http_outerror
  log_input_output
  core

Filter Chain:
  modperl_request_output           <-- the second PrintFilterChain
  byterange
  content_length
  http_header
  http_outerror
  log_input_output
  core

You see the 3 filters above the second PrintFilterChain have gone.

Now a text/html doc:

Filter Chain:                      <-- the 1st invocation sees the same chain
  modperl_request_output
  modperl_request_output
  includes
  modperl_request_output
  byterange
  content_length
  http_header
  http_outerror
  log_input_output
  core

Filter Chain:
  includes                         <-- but now the includes filter remains
  modperl_request_output
  byterange
  content_length
  http_header
  http_outerror
  log_input_output
  core


Hope that helps.

Torsten

--
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net

Re: filter->remove

Posted by Torsten Foertsch <to...@gmx.net>.
On Fri 18 Apr 2008, adam.prime@utoronto.ca wrote:
> This leads me to believe that i could write a filter that sat at the  
> head of the chain, which looked through all the filters in the chain,  
> and if appropriate removed random ones through the chain.
>
> I have a situation where i have a CGI which sometimes returns  
> text/html, and sometimes returns text/csv, but IE chokes if the csv is  
> gzipped by deflate.  I've had to disable deflate on ALL cgi's as a  
> result, but this seems like i could just create a filter that runs on  
> CGI's, that looks for a pnote that indicates that deflate should be  
> taken out of the chain.
>
> Is that correct?

Yes, I think that is correct. In fact I believe to remember there is a test in 
the modperl test suite that does just that.

Here it is: t/filter/both_str_native_remove.t

Torsten

--
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net

Re: filter->remove

Posted by ad...@utoronto.ca.
Quoting Torsten Foertsch <to...@gmx.net>:

> On Thu 17 Apr 2008, woinshet abdella wrote:

> Here an output example for text/plain:
>
> Filter Chain:
>   modperl_request_output           <-- the first PrintFilterChain
>   modperl_request_output           <-- RemoveNextFilterIfNotTextHtml
>   includes
>   modperl_request_output           <-- PrintFilterChain again
>   byterange
>   content_length
>   http_header
>   http_outerror
>   log_input_output
>   core
>
> ...

This leads me to believe that i could write a filter that sat at the  
head of the chain, which looked through all the filters in the chain,  
and if appropriate removed random ones through the chain.

I have a situation where i have a CGI which sometimes returns  
text/html, and sometimes returns text/csv, but IE chokes if the csv is  
gzipped by deflate.  I've had to disable deflate on ALL cgi's as a  
result, but this seems like i could just create a filter that runs on  
CGI's, that looks for a pnote that indicates that deflate should be  
taken out of the chain.

Is that correct?

Adam