Vary header not respected by Netlify's cache?

Hello,

Our site name is gatsby-chefclub.netlify.app
We use redirects to proxy our backend.
One or our backend route answers differently based on the Accept header: it will either give a direct JSON response or a 301 redirection depending on this header.
Our backend’s response also sends a Vary header with the Accept value, so any cache should include the client’s Accept header.
But it seems that Netlify doesn’t respect the Vary header.

We made 2 cUrl requests to the same URL, with different Accept headers (one with application/json-redirect+json and the other with text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9), and both answers were the same.
x-nf-request-ids are d2bbd229-5596-456f-b0f2-f006c089cf93-16005669 and d2bbd229-5596-456f-b0f2-f006c089cf93-16011194

Could you confirm? And if confirmed, do you have a solution?

Thanks,

Sylvain

Hi Netlify team,

Have you seen this problem? Could you confirm?

Thanks

Hey there,
Sorry for the slow response here! I see that you’ve been waiting on us for several weeks now- next time, you can write to us at support@netlify.com from an email address associated with your Pro account and we’ll get back to you faster than we did this time.

I’ve raised your question with the team that’s most familiar with our server header logic. We’ll get back to you as soon as we know more.

Following up: our CTO explained that we use the Vary header to control how our redirects work. What you’re seeing is that we override whatever value you set for that header with our value. He notes that we are unlikely to change this as it will break our caching in various ways. Would it be possible for you to set a custom header on some or all page paths, and have your backend respond to what you set there? Here are our docs on custom headers:

Please let us know if you have follow up questions!

I believe that this causes issues with next.js 13 where the browser will present raw text instead of the page, see: