How to avoid IIS from overwriting some HTTP Headers

asp.net-mvccompressionhttpiis-7iis-7.5

I have enabled in my Web.config the GZIP compression, and I'm glad that it automatically adds the HTTP header "Vary: Accept-Encoding".

The problem is that IIS is overwriting the "Vary:*" that ASP.NET returns by default.

The issue is that in POST calls, the "Vary" header has to be "*", because it means the response depends on things that are not in the URL or the HTTP headers… as far as I know. A POST call with a "Vary:Accept-Encoding" could be wrongly cached, am I right?

What I want to do is tell IIS to respect the previous "Vary" header if any.

Regards.

Best Answer

A POST request should never be cached unless it's explicitly allowed to be by either a Cache-Control or Expires header in the response. The Vary header can be used by a proxy server to optimize the decision if it can return a cached response but that's only if the response was allowed to be cached in the first place. So if you make sure the response of your POST request is not allowed to be cached, the Vary header will/should not make it cacheable whatever it is set to.