question about extending nginx_perl

Roman Vasilyev roman at anchorfree.com
Sat Feb 26 02:35:45 MSK 2011


Hi,

I need to intercept cookies while it setting in upstream module. To make 
it controllable throw reverse proxy. I want to use for this purpose 
ngx_perl, but it contains embedding only for getting headers_in  and 
creating headers_out. So I need ability to iterate throw it at rewrite 
stage and iterate throw upstream.headers_out on content stage.

I guess nginx.conf will looks like:

perl/lib/filter.pm:

package filter;
use nginx;

sub handler {
   my $r = shift;
         while(my $header=$r->upstream->header_out_get_next()){
             if($header->name eq 'Set-Cookie'){
                 #do something with cookie
                 #....
                 $header->value("new value");
             }

   return OK;
}

1;
__END__


   server {
     location / {

     perl_rewrite '
       sub {
         my $r = shift;
         while(my $header=$r->header_in_get_next()){
             if($header->name eq 'Cookie'){
                 #do something with cookie
                 #....
                 $header->value("new value");
             }
         }
       }
     ';

       perl  filter::handler;
     }
   }




More information about the nginx mailing list