Hi! I created some API methods for a few of my plugins. I want to return, as part of the header, important information, such as 'expires' and 'maxage'. The thing is that, if I use format=JSON or format=JSON2, the headers are being deleted (and replaced by 'Cache-Control: must-revalidate'). If I make the request using, for example, format=XML, I get the response with the right headers (the ones I defined in the API method of my plugin). Why is this happening? Why the format required is interfering with the headers of the response?
I'm assigning the headers like this:
header("Cache-Control: public, max-age=$maxAge");
Just before the "return" of the method.
Thank you very much.
I consider this issue as an important one: one of the most interesting things when using matomo is the ability to provide APIs that expose metrics already computed and ready to be consumed by an external process.
It is also very interesting to cache those metrics so as not to overwelm the matomo instance, however, this is not possible if the API code is not able to specify the cache control http headers.
I reckon they only way be to listen to a controller event see https://developer.matomo.org/api-reference/events#controllermoduleaction like you could listen to
Controller.API.index and then depending on the requested API method send a different header.
By the looks this is the only way so far I can think of since we're by default always sending these headers.
BTW for development questions we have a forum category: https://forum.matomo.org/c/plugins-platform