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

Added option to configure custom request content processing logic #325

Merged
merged 9 commits into from Jun 25, 2014
Merged

Added option to configure custom request content processing logic #325

merged 9 commits into from Jun 25, 2014

Conversation

sslavic
Copy link
Contributor

@sslavic sslavic commented Jun 23, 2014

This patch adds option to configure custom request content processing logic which gets called before request content is sent to tracker.

@sslavic
Copy link
Contributor Author

sslavic commented Jun 23, 2014

Tried to fix [1]st build failure with upgrade of qunit, but that didn't work out well, build failed again [2] and now with even more errors. Wish I could run the build locally before making more changes, but development environment setup for piwik project is not trivial.

[1] https://travis-ci.org/piwik/piwik/jobs/28220740
[2] https://travis-ci.org/piwik/piwik/jobs/28225867

@mattab
Copy link
Member

mattab commented Jun 24, 2014

Thanks for the pull request.

Feedback:

  • Running the tracker tests should be quite straightforward, what problem did you experience? to run the Javascript tests go to: localhost/piwik/tests/javascript/
  • The test failed because the code was not JSLint. Error was: Test failed in module externals: 'JSLint' Error: JSLint. Go to: http://jslint.com/ and there you can test that piwik.js code is lint.
  • to make sure that in the future we do not break this new feature, please add a new test case similar to this one that shows this new method works and allows you to modify request

@sslavic
Copy link
Contributor Author

sslavic commented Jun 24, 2014

jslint issues fixed, unit tests provided. Build is successful, only run on one environment failed because of environment issue as a dependency could not be installed (for more details see https://travis-ci.org/piwik/piwik/builds/28309234 )

Now I see I need another related configuration option - possibility to configure POST request Content-Type header value. Currently it's hardcoded to 'application/x-www-form-urlencoded; charset=UTF-8'

@sslavic
Copy link
Contributor Author

sslavic commented Jun 24, 2014

Again, environment issues, this time in two build steps, failed the entire build (see https://travis-ci.org/piwik/piwik/builds/28321164 ) but Javascript tests build step and 11 other steps ran well.

* @param string requestContentType; default is 'application/x-www-form-urlencoded; charset=UTF-8'
*/
setRequestContentType: function (requestContentType) {
configRequestContentType = requestContentType || 'application/x-www-form-urlencoded; charset=UTF-8';
Copy link
Member

Choose a reason for hiding this comment

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

the default value is not needed here because it is set to default above (it's best to avoid duplication when possible)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's a bit redundant, deliberately, to be consistent with existing code, e.g. setRequestMethod. When you think of it, it's like a safe setter, if setter is called without providing value. To be DRY and keep setters safe, we could make in both cases default value to be a separate non mutable field.

@mattab
Copy link
Member

mattab commented Jun 24, 2014

I see I need another related configuration option - possibility to configure POST request Content-Type header value

could you tell me the use case where you want to change the content-type?

@mattab
Copy link
Member

mattab commented Jun 24, 2014

Again, environment issues,

Yes you're right all these build failures are random and not caused by your change. We have this issue regularly and we will try to keep minimising the random build failure issue.

The tests you added are nicely done!

@sslavic
Copy link
Contributor Author

sslavic commented Jun 25, 2014

With new method one can change request content not to be query parameters string, but a JSON or XML, or something else, and in these cases previously hardcoded form content type header value is not appropriate. So, since content can be customized, IMO content type header should be customizable as well so one can change it to match actual content; having one option without other would be incomplete.

@sslavic
Copy link
Contributor Author

sslavic commented Jun 25, 2014

I've made default request method and request content type value DRY, while keeping setters safe. Build is all green.

mattab pushed a commit that referenced this pull request Jun 25, 2014
Added option to configure custom request content processing logic fixes #5384
@mattab mattab merged commit 46b2726 into matomo-org:master Jun 25, 2014
@mattab
Copy link
Member

mattab commented Jun 25, 2014

method was renamed in: a0c1fee

and documentation updated in: matomo-org/developer-documentation@bc29074

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.

None yet

2 participants