Forum: NGINX Overwriting a request cookie with a variable

Posted by Markus Jelsma (Guest)
on 2010-02-05 17:56
(Received via mailing list)
Hello list,


I have managed to retrieve data from memcache in a variable using the 
eval
module in Nginx but now i need that variable to be injected into the 
current
HTTP request.

Scenario:
An incoming HTTP request carries a cookie named token. I use that token 
to
look up a value in memcache. Afterwards, i need to replace the original 
token
cookie value with that new value i got from memcache before proxying the
request to a backend.

I have looked in the wiki and figured i need to write a variable, but 
writing
to my cookie doesn't seem to work. Also, i have not seen any leads in 
the
HttpCoreModule documentation on how to set/overwrite/manipulate a 
variable
from the HTTP request.


Regards,

Markus Jelsma - Technisch Architect - Buyways BV
http://www.linkedin.com/in/markus17
050-8536620 / 06-50258350
Posted by Maxim Dounin (Guest)
on 2010-02-05 19:00
(Received via mailing list)
Hello!

On Fri, Feb 05, 2010 at 04:15:31PM +0100, Markus Jelsma wrote:

> cookie value with that new value i got from memcache before proxying the 
> request to a backend.
> 
> I have looked in the wiki and figured i need to write a variable, but writing 
> to my cookie doesn't seem to work. Also, i have not seen any leads in the 
> HttpCoreModule documentation on how to set/overwrite/manipulate a variable 
> from the HTTP request.

You have to use

   proxy_set_header Cookie $variable;

and carefully construct $variable from original $http_cookie
header and data you got from memcached.  Refer to relevant specs
for Cookie header syntax, and use "if" with regexp matching and
"set" to do it.

If you have control over backend - I recommend you not to replace
it, but use some custom header instead, e.g.

   proxy_set_header X-Memcached-Data $data;

Maxim Dounin
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.