Welcome! Log In Create A New Profile

Advanced

Re: How to change cookie header in a filter?

Maxim Dounin
March 19, 2013 09:06AM
Hello!

On Mon, Mar 18, 2013 at 04:24:05PM -0700, Cool wrote:

> Hi,
>
> What's the right way to change incoming cookie header so that upstream
> can get it just like it's from user's original request header? For
> example, user's browser sends:
>
> Cookie: PHPSESSID=34406134e25e5e07727f5de6d5ff7aa3; __utmc=78548747
>
> and I want it to be:
>
> Cookie: PHPSESSID=34406134e25e5e07727f5de6d5ff7aa3; __utmc=78548747;
> mycookie=something
>
> when upstream processes the request.

I would recommend something like this:

proxy_set_header Cookie "$http_cookie; mycookie=something";

(Similar to what's usually done with X-Forwarded-For using
the $proxy_add_x_forwarded_for variable.)

> I'm trying to migrate an Apache HTTPd module to nginx, it's more or less
> like mod_usertrack
> (http://httpd.apache.org/docs/2.2/mod/mod_usertrack.html) but I need to
> implement my own logic to enforce compatibility among Apache, Nginx,
> IIS, and Jetty.
>
> The question is, for the first time visitor, the incoming request does
> not have mycookie in the header, I can determine this and generate
> cookie and Set-Cookie in response, however, I also need to change
> incoming cookie header so that upstream (php-fpm now, but should be same
> to all other upstreams as I'm guessing) can get this generated
> "mycookie" as well.
>
> I tried to add new entry to r->headers_in.cookies but it does not work,
> also tried r->headers_in.headers but no luck either.

It's usually not a good idea to change original request headers.
Instead, it is recommended to form appropriate request to an
upstream, see above.

--
Maxim Dounin
http://nginx.org/en/donation.html

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

How to change cookie header in a filter?

Cool March 18, 2013 07:26PM

Re: How to change cookie header in a filter?

Maxim Dounin March 19, 2013 09:06AM

Re: How to change cookie header in a filter?

Cool March 19, 2013 02:52PM

Re: How to change cookie header in a filter?

Maxim Dounin March 20, 2013 04:40AM

Re: How to change cookie header in a filter?

Cool March 21, 2013 12:18PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 162
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready