You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Jason Hall <ja...@infogenix.com> on 2001/12/07 18:52:52 UTC
Apache::Filter Help Please!!
Please see if you notice anything glaringly wrong in what I'm doing.
Basically my problem is that my filter isn't passing data along, eg what I
print in filter1 isn't getting output, even though filter2 get's the
filehandle and loops over it. My setup is pretty akin to what the docs offer
in the synopsis.
in httpd.conf
------
PerlModule Apache::Filter
<Files support>
SetHandler perl-script
PerlSendHeader ON
PerlSetVar Filter On
PerlHandler Filter1 Filter2
</Files>
in the filters
---------------
sub handler
{
my $r = shift;
$r = $r->filter_register();
my ($fh, $status) = $r->filter_input();
return $status unless $status == OK;
while(<$fh>)
{
print;
}
print "Filter 2"; #filter 1 has "filter1", obviously
return OK;
}
now, according to what I've read, this should print out the "Filter 1Filter
2", which is what I need to let me get real work done, but all I get is
Filter 2. So all powerful list, WTF am I missing (it's gotta be something
obvious, it always is).
--
Jayce^
Re: Apache::Filter Help Please!!
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Jason Hall wrote:
>
> AHAH!!! I found it.. thanks, your example showed the difference.
>
> What it was is that I was sending my header before my final filter, which as
> I now am guessing, maps STDOUT, which this needs.
well, you should be able to print your headers from any filter in the
chain - they are a no-op for all but the final filter.
package One;
use Apache::Constants qw(OK);
use strict;
sub handler {
my $r = shift;
$r = $r->filter_register();
$r->send_http_header('text/plain');
print "Filter 1";
return OK;
}
1;
should work just as well...
> I'm recommending to the
> author to put a note in about where the headers should be printed.
>
> Thanks for your help, definately made the difference
no problem :)
--Geoff
Re: Apache::Filter Help Please!!
Posted by Jason Hall <ja...@infogenix.com>.
AHAH!!! I found it.. thanks, your example showed the difference.
What it was is that I was sending my header before my final filter, which as
I now am guessing, maps STDOUT, which this needs. I'm recommending to the
author to put a note in about where the headers should be printed.
Thanks for your help, definately made the difference
On Friday 07 December 2001 01:10 pm, you wrote:
> Jason Hall wrote:
> > ok, that make sense, so I modified my filter1 to just register the
> > filter, print out some text, and return ok, that's it. and it still
> > doesn't print anything if filter2 comes after it? Does that sound wrong
> > to anybody but me?
>
> try this:
>
> package One;
>
> use Apache::Constants qw(OK);
> use strict;
>
> sub handler {
> my $r = shift;
> $r = $r->filter_register();
> print "Filter 1";
> return OK;
> }
> 1;
>
> package Two;
>
> use Apache::Constants qw(OK);
> use strict;
>
> sub handler {
> my $r = shift;
> $r = $r->filter_register();
> my ($fh, $status) = $r->filter_input();
> return $status unless $status == OK;
> $r->send_http_header('text/plain');
> while(<$fh>) {
> print;
> }
> print "Filter 2";
> return OK;
> }
> 1;
>
>
> looks like if you don't send your headers things go slightly amuck.
>
> --Geoff
--
Jayce^
Re: Apache::Filter Help Please!!
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Jason Hall wrote:
>
> ok, that make sense, so I modified my filter1 to just register the filter,
> print out some text, and return ok, that's it. and it still doesn't print
> anything if filter2 comes after it? Does that sound wrong to anybody but me?
>
try this:
package One;
use Apache::Constants qw(OK);
use strict;
sub handler {
my $r = shift;
$r = $r->filter_register();
print "Filter 1";
return OK;
}
1;
package Two;
use Apache::Constants qw(OK);
use strict;
sub handler {
my $r = shift;
$r = $r->filter_register();
my ($fh, $status) = $r->filter_input();
return $status unless $status == OK;
$r->send_http_header('text/plain');
while(<$fh>) {
print;
}
print "Filter 2";
return OK;
}
1;
looks like if you don't send your headers things go slightly amuck.
--Geoff
Re: Apache::Filter Help Please!!
Posted by Jason Hall <ja...@infogenix.com>.
ok, that make sense, so I modified my filter1 to just register the filter,
print out some text, and return ok, that's it. and it still doesn't print
anything if filter2 comes after it? Does that sound wrong to anybody but me?
On Friday 07 December 2001 12:47 pm, you wrote:
> I tried out your config and handlers pretty much verbatim and got them
> to work just fine. the only real change was that I needed to comment
> out
>
> > return $status unless $status == OK;
>
> from filter one, since $fh is $r->filename for the first filter, which
> brings up 404 when the file is not found.
>
> that said, yes I see the same thing, but only for 404s. I think the
> problem is that you need to deal with your error code properly.
>
> > now, according to what I've read, this should print out the "Filter
> > 1Filter 2", which is what I need to let me get real work done, but all I
> > get is Filter 2. So all powerful list, WTF am I missing (it's gotta be
> > something obvious, it always is).
>
> $fh is $r->filename for the first filter in the chain. if
> $r->filename does not exist, you need to handle this. $status is one
> way of handling it. checking for $fh (which will be undef if
> $r->filename does not exist) is another. basically, you definitely
> don't want to read from $fh if $fh is not defined :)
>
> this situation should probably be protected against in Apache::Filter
> better, but it basically looks like it is a problem with your logic.
>
> HTH
>
> --Geoff
--
Jayce^
Re: Apache::Filter Help Please!!
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
I tried out your config and handlers pretty much verbatim and got them
to work just fine. the only real change was that I needed to comment
out
> return $status unless $status == OK;
from filter one, since $fh is $r->filename for the first filter, which
brings up 404 when the file is not found.
that said, yes I see the same thing, but only for 404s. I think the
problem is that you need to deal with your error code properly.
>
> now, according to what I've read, this should print out the "Filter 1Filter
> 2", which is what I need to let me get real work done, but all I get is
> Filter 2. So all powerful list, WTF am I missing (it's gotta be something
> obvious, it always is).
$fh is $r->filename for the first filter in the chain. if
$r->filename does not exist, you need to handle this. $status is one
way of handling it. checking for $fh (which will be undef if
$r->filename does not exist) is another. basically, you definitely
don't want to read from $fh if $fh is not defined :)
this situation should probably be protected against in Apache::Filter
better, but it basically looks like it is a problem with your logic.
HTH
--Geoff