we've found an issue recently while developing an add-on for one of our customers.
our add-on is an agenda that includes days and appointments; for days we implemented a view that shows all appointments on that day and a calendar to make navigating the agenda easy.
the calendar is build on the fly using application/json
calls to other days on the same month to mark all days with appointments and to make fast updates when a user selects another day.
resuming: if I traverse to the default view of a day, I get normal HTML; if I request application/json
using an AJAX call to the same default view, I get JSON.
everything was more or less working until we deployed it and then we discovered that Varnish was caching only one of the versions breaking the whole thing.
enters the Vary
header; according to Varnish documentation:
If the origin server sends
Vary
in a response, Varnish does not use this response to satisfy a later request unless the later request has the same values for the listed fields inVary
as the original request. As a consequence,Vary
expands the cache key required to match a new request to the stored cache entry.
so, according to this I can fix the issue adding the Vary
header to my response.
my next step was testing the following on our code:
def __call__(self):
self.setup()
self.request.response.appendHeader('Vary', 'Accept')
return self.index()
and it works fine, except for one detail: it's only applied to the HTML response.
does anybody else has found this issue? how do you deal with it?
I'm wondering why this header is not included by default in plone.restapi (any comments, @tisto?)
tomorrow I'm going to test a workaround using plone.app.caching; I'll post my results after that.