Search code examples
.netasp.net-mvc.net-corevaryresponsecache

.net core UseResponseCompression conflicts with ResponseCache attribute when putting Vary header values


I am using the Response Compression Middleware in my .Net Core API application by calling app.UseResponseCompression(). But in one of my API controller actions, I'm also using ResponseCache attribute and setting it to VaryByHeader = Authorization but the response I'm getting only gets the header Vary: "Accept-Encoding" which seems to be getting put there by the Response Compression middleware. If I remove the middleware the Vary: Authorization shows up so I'm guessing the middleware is conflicting with the ResponseCache attribute.

How would I be able to get the Authorization on the vary Header while also using still being able to use the Response Compression Middleware?


Solution

  • Apparently I have to put both "Accept-Encoding" and "Authorization" for the VaryByHeader value in order to get them both, if using ResponseCache attribute with UseResponseCompression middleware. I'm not sure why this is the case though.

    I put them as a comma separated values i.e. "Accept-Encoding, Authorization" for the VaryByHeader property of the ResponseCache attribute.