Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headers deleted/replaced when format=JSON #15476

Closed
eramirezprotec opened this issue Jan 28, 2020 · 2 comments
Closed

Headers deleted/replaced when format=JSON #15476

eramirezprotec opened this issue Jan 28, 2020 · 2 comments
Labels
answered For when a question was asked and we referred to forum or answered it.

Comments

@eramirezprotec
Copy link
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.

@eramirezprotec eramirezprotec changed the title Headers deleted when format=JSON Headers deleted/replaced when format=JSON Jan 28, 2020
@pardvm
Copy link

pardvm commented Jan 28, 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
Copy link
Member

tsteur commented Jan 28, 2020

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

@tsteur tsteur closed this as completed Jan 28, 2020
@tsteur tsteur added the answered For when a question was asked and we referred to forum or answered it. label Jan 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered For when a question was asked and we referred to forum or answered it.
Projects
None yet
Development

No branches or pull requests

3 participants