Ruby Forum NGINX > Setting headers and cookies when proxying

Posted by Guy Naor (Guest)
on 16.08.2008 03:29
(Received via mailing list)
Hi,

I am trying to write a module that will insert a header into the request
that is sent to the upstream servers (mongrels). I can set headers based 
on
the code found in some other modules, but all set the header on the 
response
headers, not the headers proxied forward. I also would like to set a 
cookie
in the same form - add a cookie to the headers that will be passed to 
the
upstream servers.

Any ponters as to where to look for something like that? Or some other
information that could help?

This is to be used in a multi-server load-balancing situation that 
require
client stickiness. My plan is to release this code so others could use 
it
once it's stable.

Bye,

Guy.
Posted by Maxim Dounin (Guest)
on 16.08.2008 05:38
(Received via mailing list)
Hello!

On Fri, Aug 15, 2008 at 06:22:45PM -0700, Guy Naor wrote:

>information that could help?
Um.  Just use proxy_set_header directive and allow user to
configure it by hand (e.g. using variable from your module)?

You probably may modify r->headers_in too, but I'm not sure it's a
good idea.

Maxim Dounin
Posted by Igor Sysoev (Guest)
on 16.08.2008 07:19
(Received via mailing list)
On Fri, Aug 15, 2008 at 06:22:45PM -0700, Guy Naor wrote:

> This is to be used in a multi-server load-balancing situation that require
> client stickiness. My plan is to release this code so others could use it
> once it's stable.

As it was already suggested, you do not need a module for this, you may
use configuration:

        proxy_set_header  header   value;
Posted by Guy Naor (Guest)
on 16.08.2008 07:41
(Received via mailing list)
Hi,

That will set a header, but will not allow me to set a cookie. If I use:

set_proxy_header Cookie whatever=something;

It overwrites the cookies sent by the browser. Is there a way to add a
cookie this way?

Bye,

Guy.
Posted by Igor Sysoev (Guest)
on 16.08.2008 07:48
(Received via mailing list)
On Fri, Aug 15, 2008 at 10:35:40PM -0700, Guy Naor wrote:

> That will set a header, but will not allow me to set a cookie. If I use:
> 
> set_proxy_header Cookie whatever=something;
> 
> It overwrites the cookies sent by the browser. Is there a way to add a 
> cookie this way?

set_proxy_header Cookie "whatever=something;$http_cookie";