You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Tatsuhiko Miyagawa <mi...@edge.co.jp> on 2002/07/04 14:44:42 UTC

touch Apache::RequestRec in OutputFilter phase?

if I want to modify HTTP response header in OutputFilter phase, I
should configure httpd.conf as PerlOptions +GlobalRequest, and then I
can get $r with Apache->request.

Am I right in saying this?

P.S. Following code is any to any encoding filter, paticulary useful
in development for co-existence with PC browsers and Japanese phone
browsers, etc.


package Slasher::EncodingFilter;

use strict;

use Apache::RequestRec ();
use Apache::RequestIO ();
use Apache::Filter ();
use Encode;
use I18N::Charset;

use Apache::Const -compile => 'OK';

sub handler {
    my $filter = shift;
    my $r = Apache->request;
    my($from, $to) = map $r->dir_config($_), qw(EncodingFrom EncodingTo);
    my $charset = iana_charset_name($to);
    $r->content_type("text/html; charset=$charset");
    while ($filter->read(my $buffer, 1024)) {
        Encode::from_to($buffer, $from, $to);
        $filter->print($buffer);
    }
    return Apache::OK;
}

1;

__END__
PerlModule Slasher::EncodingFilter
<Location /charset>
PerlSetVar EncodingFrom euc-jp
PerlSetVar EncodingTo  utf8
PerlOptions +GlobalRequest
PerlOutputFilterHandler Slasher::EncodingFilter
</Location>




  
--
Tatsuhiko Miyagawa <mi...@edge.co.jp>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: touch Apache::RequestRec in OutputFilter phase?

Posted by Stas Bekman <st...@stason.org>.
Tatsuhiko Miyagawa wrote:
> At Fri, 05 Jul 2002 19:30:56 +0800,
> Stas Bekman wrote:
>  
> 
>>Yes, but there is an easier and *much* more effective way.
>>
>>Your handler is really FilterRequestHandler (which is the default 
>>attribute) so you have the request object already.
>>
>>sub handler : FilterRequestHandler {
>>     my $filter = shift;
>>     ...
>>     $filter->r->content_type("text/html; charset=$charset");
> 
> 
> neat, thanks ;)
> 
> but is that already documented somewhere, other than XS glue code?

I'm working on this.

For now if anything is not documented you should be able to find in t/, 
since most of the basic features are tested. in this particular case 
t/filter/TestFilter/api.pm is what you need.

__________________________________________________________________
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


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: touch Apache::RequestRec in OutputFilter phase?

Posted by Tatsuhiko Miyagawa <mi...@edge.co.jp>.
At Fri, 05 Jul 2002 19:30:56 +0800,
Stas Bekman wrote:
 
> Yes, but there is an easier and *much* more effective way.
> 
> Your handler is really FilterRequestHandler (which is the default 
> attribute) so you have the request object already.
> 
> sub handler : FilterRequestHandler {
>      my $filter = shift;
>      ...
>      $filter->r->content_type("text/html; charset=$charset");

neat, thanks ;)

but is that already documented somewhere, other than XS glue code?


-- 
Tatsuhiko Miyagawa <mi...@edge.co.jp>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: touch Apache::RequestRec in OutputFilter phase?

Posted by Stas Bekman <st...@stason.org>.
Tatsuhiko Miyagawa wrote:
> if I want to modify HTTP response header in OutputFilter phase, I
> should configure httpd.conf as PerlOptions +GlobalRequest, and then I
> can get $r with Apache->request.
> 
> Am I right in saying this?

Yes, but there is an easier and *much* more effective way.

Your handler is really FilterRequestHandler (which is the default 
attribute) so you have the request object already.

sub handler : FilterRequestHandler {
     my $filter = shift;
     ...
     $filter->r->content_type("text/html; charset=$charset");
     ...
}

__________________________________________________________________
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


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org