You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Issac Goldstand <ma...@beamartyr.net> on 2002/12/02 20:31:55 UTC

[MP2] Handler feauters in a filter?

I'm writing a filter in which two lines of data are to be appended to the
content going back.  However, I'd like to test for a 404, and if found set
the response to 200.  Can this be done from the output filters?  Or am I
going to have to do something more complex with a handler?

The big problem is mod_proxy (or any other module, for that matter) - it's
not as simple as checking the file on disk - the content could be coming
from a proxy or from another content-handler.

Any ideas?
  Issac


Re: [MP2] Handler feauters in a filter?

Posted by Issac Goldstand <ma...@beamartyr.net>.
----- Original Message -----
From: "Stas Bekman" <st...@stason.org>
> Issac Goldstand wrote:
> > Not sure how to translate that to mod_perl's API (the first half is easy
and
> > understandable in C, I think, though...)
>
> It works exactly the same, just add $ before 'f' :) Though you don't say
> where in the filter chain do you insert it and how do you configure it
> (i.e. what filter type).

Oops.  It's an output filter hooked at the resource hook area.  It works
properly with both static files and with mod_proxy (I'm assuming also with
any other content handlers).  I *really* don't like the way I just sorta
hacked the response (it would be kinda neat if I could trigger Apache to
regenerate $r->Status_line properly on its own), but whatever...

  Issac


Re: [MP2] Handler feauters in a filter?

Posted by Stas Bekman <st...@stason.org>.
Issac Goldstand wrote:
> Implemented it in C:
> 
>   if (f->r->status==HTTP_NOT_FOUND) // If this is so, we need to revamp the
> request_rec
>   {
>    f->r->status=HTTP_OK; // Spoof HTTP_OK
>    f->r->status_line="200 OK";
> 
> APR_BRIGADE_INSERT_TAIL(ctx->bb,apr_bucket_eos_create(f->c->bucket_alloc));
> // Add an EOS to the new bb
>    ap_pass_brigade(f->next,ctx->bb); // and pass the new bb to the next
> filter
>    return APR_SUCCESS;
>   }
> 
> Not sure how to translate that to mod_perl's API (the first half is easy and
> understandable in C, I think, though...)

It works exactly the same, just add $ before 'f' :) Though you don't say 
where in the filter chain do you insert it and how do you configure it 
(i.e. what filter type).

> This was *my* solution - I'm not sure if it's the "best way to do it"...
> I'm sure that as I delve deeper into Apache 2, I'll find better solutions...

Hence my suggestion to ask at the httpd-dev list.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: [MP2] Handler feauters in a filter?

Posted by Issac Goldstand <ma...@beamartyr.net>.
Implemented it in C:

  if (f->r->status==HTTP_NOT_FOUND) // If this is so, we need to revamp the
request_rec
  {
   f->r->status=HTTP_OK; // Spoof HTTP_OK
   f->r->status_line="200 OK";

APR_BRIGADE_INSERT_TAIL(ctx->bb,apr_bucket_eos_create(f->c->bucket_alloc));
// Add an EOS to the new bb
   ap_pass_brigade(f->next,ctx->bb); // and pass the new bb to the next
filter
   return APR_SUCCESS;
  }

Not sure how to translate that to mod_perl's API (the first half is easy and
understandable in C, I think, though...)

This was *my* solution - I'm not sure if it's the "best way to do it"...
I'm sure that as I delve deeper into Apache 2, I'll find better solutions...

  Issac

----- Original Message -----
From: "Stas Bekman" <st...@stason.org>
To: "Issac Goldstand" <ma...@beamartyr.net>
Cc: <mo...@perl.apache.org>
Sent: Tuesday, December 03, 2002 3:43 PM
Subject: Re: [MP2] Handler feauters in a filter?


> Issac Goldstand wrote:
> > I'm writing a filter in which two lines of data are to be appended to
the
> > content going back.  However, I'd like to test for a 404, and if found
set
> > the response to 200.  Can this be done from the output filters?  Or am I
> > going to have to do something more complex with a handler?
>
> Haven't tried this yet, but you can either write a connection filter
> which rewrites the headers if they were sent already, or insert your
> filter just before the one that generates the headers. Since you want to
> add something to the end, the former case is probably the best. I
> suggest that you ask for the best way at the httpd-dev list, as it's a
> pretty generic httpd topic and that list has real filter experts. Then
> once you figure out from them what's the best way to go (and share with
> us :) implementing it in perl is a piece of cake.
>
> > The big problem is mod_proxy (or any other module, for that matter) -
it's
> > not as simple as checking the file on disk - the content could be coming
> > from a proxy or from another content-handler.
> >
> > Any ideas?
> >   Issac
>
>
> --
>
>
> __________________________________________________________________
> Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/     mod_perl Guide ---> http://perl.apache.org
> mailto:stas@stason.org http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org   http://ticketmaster.com
>


Re: [MP2] Handler feauters in a filter?

Posted by Stas Bekman <st...@stason.org>.
Issac Goldstand wrote:
> I'm writing a filter in which two lines of data are to be appended to the
> content going back.  However, I'd like to test for a 404, and if found set
> the response to 200.  Can this be done from the output filters?  Or am I
> going to have to do something more complex with a handler?

Haven't tried this yet, but you can either write a connection filter 
which rewrites the headers if they were sent already, or insert your 
filter just before the one that generates the headers. Since you want to 
add something to the end, the former case is probably the best. I 
suggest that you ask for the best way at the httpd-dev list, as it's a 
pretty generic httpd topic and that list has real filter experts. Then 
once you figure out from them what's the best way to go (and share with 
us :) implementing it in perl is a piece of cake.

> The big problem is mod_proxy (or any other module, for that matter) - it's
> not as simple as checking the file on disk - the content could be coming
> from a proxy or from another content-handler.
> 
> Any ideas?
>   Issac


-- 


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com