@eramirezprotec opened this Issue on January 28th 2020 Contributor

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.

@pardvm commented on January 28th 2020

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.

@tsteur commented on January 28th 2020 Member

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. and 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

This Issue was closed on January 28th 2020
Powered by GitHub Issue Mirror