# Selectively implement something like proxy\_ignore\_headers Set-Cookie?

**URL:** <https://www.ruby-forum.com/t/selectively-implement-something-like-proxy-ignore-headers-set-cookie/227249>\
**Category:** NGINX\
**Created:** [March 8, 2013, 6:04pm UTC](https://www.ruby-forum.com/t/selectively-implement-something-like-proxy-ignore-headers-set-cookie/227249 "2013-03-08T18:04:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [March 8, 2013, 6:04pm UTC](https://www.ruby-forum.com/t/selectively-implement-something-like-proxy-ignore-headers-set-cookie/227249/1 "2013-03-08T18:04:20Z")

</div>

I’m wondering if anyone has any thoughts about how I might address the  
following?

I am using nginx as a caching reverse proxy in front of a complex  
Apache/Weblogic Java application.

I have a half-dozen Location blocks that have different caching policies  
with custom keys and

different cache lifetimes. I’m using openresty to implement different  
cache key logic with lua scripts

and until now everything has gone smoothly.

Some of the locations use the combination of

proxy\_ignore\_headers Set-Cookie and proxy\_hide\_header Set-Cookie to  
strip cookies from cached responses.

Another location needs to allow for session cookies to be created and so  
it has the default nginx behavior of not caching

responses that contain cookies.

Now I need a different hybrid behavior-

if a response contains “Set-Cookie: TLTHID”, then strip it from the  
response, but still cache the response.

If the response contains any other Set-Cookie header then don’t cache  
the response.

I have tried to use more\_clear\_headers 'Set-Cookie: TLTHID\*" to strip  
the cookie and I see

that it does indeed remove the cookie from the response, however the  
debug log shows me that the object is still

seen as being not cacheable, presumably because nginx knows that the  
stripped Set-Cookie was there.

Is there an easy way to work around this? I’d considered running a  
second nginx process to simply act as a

proxy that strips the 'Set-Cookie: TLTHID\*" header - it sounds clunky  
but I expect it would work.

Is there a way to achieve this within a single nginx instance?

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [March 8, 2013, 7:45pm UTC](https://www.ruby-forum.com/t/selectively-implement-something-like-proxy-ignore-headers-set-cookie/227249/2 "2013-03-08T19:45:28Z")

</div>

On 8 March 2013 17:00, Peter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Now I need a different hybrid behavior-
> 
> if a response contains “Set-Cookie: TLTHID”, then strip it from the  
> response, but still cache the response.
> 
> If the response contains any other Set-Cookie header then don’t cache the  
> response.
> 
> Is there a way to achieve this within a single nginx instance?

I don’t use nginx as a cache, so I can’t speak as for how this will  
work with the caching subsystem, but I wonder if something like this  
might work:

* * *

map $sent\_http\_set\_cookie $header\_to\_drop {  
default NA;  
~TLTHID Set-Cookie;  
}

## server { proxy\_pass [http://upstream.fqdn](http://upstream.fqdn); proxy\_ignore\_headers $header\_to\_drop; proxy\_hide\_header $header\_to\_drop; }

The map might need $upstream\_http\_set\_cookie instead - I don’t recall  
the difference off the top of my head.

## HTH, Jonathan

Jonathan M. // Oxford, London, UK

> **[Jonathan Matthews :: Words Typed, Great Rates For Cash](https://www.jpluscplusm.com)**
