# Question about extending nginx\_perl

**URL:** <https://www.ruby-forum.com/t/question-about-extending-nginx-perl/203738>\
**Category:** NGINX\
**Created:** [February 26, 2011, 12:38am UTC](https://www.ruby-forum.com/t/question-about-extending-nginx-perl/203738 "2011-02-26T00:38:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [February 26, 2011, 12:38am UTC](https://www.ruby-forum.com/t/question-about-extending-nginx-perl/203738/1 "2011-02-26T00:38:12Z")

</div>

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

```

}

---

<div class="post-metadata">

**Author:** ![Roman\_V](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc8723/32.png) [@Roman\_V](https://www.ruby-forum.com/u/Roman_V)\
**Post date:** [February 26, 2011, 12:40am UTC](https://www.ruby-forum.com/t/question-about-extending-nginx-perl/203738/2 "2011-02-26T00:40:05Z")

</div>

Forgot the question 🙂

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