Skip to content

Method setRequestMethodNonBulk() added to allow (non bulk) POST requests #71

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

Merged
merged 8 commits into from
Jul 16, 2020
Merged

Method setRequestMethodNonBulk() added to allow (non bulk) POST requests #71

merged 8 commits into from
Jul 16, 2020

Conversation

silvershadowcc
Copy link
Contributor

@silvershadowcc silvershadowcc commented Jul 12, 2020

POST was already supported, because it's used for BulkTrack. This method should provide the option to choose POST in other scenarios (when using setTokenAuth for increased security for example).

@silvershadowcc
Copy link
Contributor Author

Would be able to solve #43

@tsteur
Copy link
Member

tsteur commented Jul 12, 2020

Thanks @silvershadowcc

btw there will be likely still few more changes needed so that the token actually gets posted and not sent through a URL query parameter.

added warning about redirects for setRequestMethod()
prevent method from being set to GET while doing Bulk Requests
@silvershadowcc silvershadowcc marked this pull request as draft July 13, 2020 10:31
Method is now set to POST as bool, instead of a string, since it should remain defaulted to GET and there is no need to have the option to set it to GET.

URL is spliced in URL and parameters which are now fed to the POST payload for both cURL and stream.
@silvershadowcc
Copy link
Contributor Author

Thanks @silvershadowcc

btw there will be likely still few more changes needed so that the token actually gets posted and not sent through a URL query parameter.

Sorry, I assumed that the parameters would actually be posted haha. Changed it, this works.
Perhaps the variable/method names should be changed and I don't know if this structure is acceptable?

As stated in the commit:
The request method is now set to POST as boolean, instead of a string, since the method should remain defaulted to GET and there is no need to be able to set it to GET.

URL is spliced in URL and parameters which are now fed to the POST payload for both cURL and stream.

@silvershadowcc silvershadowcc marked this pull request as ready for review July 13, 2020 15:10
@tsteur
Copy link
Member

tsteur commented Jul 13, 2020

The namings are all good @silvershadowcc 👍

The request method is now set to POST as boolean, instead of a string, since the method should remain defaulted to GET and there is no need to be able to set it to GET.

I wonder if any one would use any other kind of request methods like PUT or HEAD. I suppose that's not the case. Might be more flexible to force users to specify eg POST.

I'll try to test this in the next days @silvershadowcc looking only at the code it looks good.

The next step after this would be to see if we can somehow make POST the default for the token_auth only and send other URL parameters still via GET. Why? This way it's still possible to reply requests using our log importer. What happens is then that in eg apache or nginx log the requests will be found like

IP ... GET matomo.php?action_name=foo&idsite=1&rec=1 ...

and someone else can then replay these actions. Vs with a POST of all parameters we would only see POST matomo.php. People use log analytics to replay requests if there was a downtime, if they are performing a long lasting upgrade, or in general always. Eg it's a lot faster to not process any of the tracking requests in real time but rather once a day or a few times a day reply all tracking requests from the logs at once. It's not too important but wanted to provide a bit of background. We don't have to do this as part of this PR but as a next step as part of #43 .

We would already POST the token by default. However, we can do this only once we make sure redirected URLs get the value posted as well.

Snake case converted to camel case. Reverted back to the method selection of 'POST' (intended). Added a warning about Log Analytics.
@silvershadowcc
Copy link
Contributor Author

silvershadowcc commented Jul 14, 2020

Went back to the previous selection of POST as string. Currently no other methods would be supported since they may require different input for cURL and stream. Converted snake to camel casing and added the warning. Thanks for the background. Making sure that redirected URLs get the POST values might be as easy as using curl -L --post301 --post302, right?

The next step after this would be to see if we can somehow make POST the default for the token_auth only and send other URL parameters still via GET.

Do you mean sending a POST request with the token_auth as payload, but everything else still as GET? If so, it would be just as easy to implement it that way now (and fixing the potential redirect problem). The preferred method for this would be to use a GET request with HTTP Authorization header though, which would bring us back to #matomo-org/matomo#7349

Copy link
Member

@tsteur tsteur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@silvershadowcc looking good. It worked for me. Left one more comment before merging. Basically we need to rename a method. I started working on the final solution with security by default in mind in #72

I had to start working on this to make sure by merging this we won't need to change everything again later when we develop the "security by default" solution. Otherwise we would have needed to provide eg backwards compatibility for this new public method etc even though it would have been barely used. But the method will still be needed later so it's all good.

If after merging this you are keen on giving #72 a try feel free to go ahead.

@silvershadowcc silvershadowcc changed the title function setRequestMethod added for POST Method setRequestMethodNonBulk() added to allow (non bulk) POST requests Jul 15, 2020
@silvershadowcc
Copy link
Contributor Author

silvershadowcc commented Jul 16, 2020

If after merging this you are keen on giving #72 a try feel free to go ahead.

Tomorrow :) But I can't test bulk. I added that only POST and GET are supported for docs in the latest commit.

@tsteur
Copy link
Member

tsteur commented Jul 16, 2020

Thanks @silvershadowcc

@tsteur tsteur merged commit effc715 into matomo-org:master Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants