Question about extending nginx_perl

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;
 }

}

Forgot the question :slight_smile:

What best way to do it? Or maybe this is doable with current embedded
perl other way?