cloudflare / lua-resty-cookie

Lua library for HTTP cookie manipulations for OpenResty/ngx_lua
347 stars 160 forks source link

Add API for updating/serializing cookie table #34

Open mamacdon opened 4 years ago

mamacdon commented 4 years ago

I'm trying to use this library in a reverse proxy that modifies a cookie header before passing the request to the upstream. For example, if an incoming request has this header:

Cookie: a=1; b=2; c=3

I want to parse it, remove b and change the value of a, producing a value like:

a=4; c=3

After that, I use a directive like proxy_set_header Cookie $new_cookies to override the cookies sent to the upstream.

Right now I can't cleanly accomplish this using lua-resty-cookie. I can parse the incoming Cookie header using get_all(), but I have to filter/modify/assemble the resulting cookie myself.

It would be helpful to have API for updating values inside the cookie table, and serializing the table to the format used in a Cookie header. E.g. something like this:

Would this fit within the scope of this library? Or is this project intended only as a wrapper for Set-Cookie?

Arryboom commented 2 years ago

yes 2021 we still need it!