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 support for sending and reading Tracker Cookies #28

Merged
merged 1 commit into from Nov 9, 2017

Conversation

MichaelRoosz
Copy link

These functions are needed by some new tests I wrote for the QueuedTracking plugin. With them it is possible to send and read the third party cookie set by Piwik.

@MichaelRoosz
Copy link
Author

@@ -1583,6 +1591,8 @@ protected function sendRequest($url, $method = 'GET', $data = null, $force = fal
if (!empty($response)) {
list($header, $content) = explode("\r\n\r\n", $response, $limitCount = 2);
}

$this->parseIncomingCookies(explode("\r\n", $header));
Copy link
Member

Choose a reason for hiding this comment

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

When I tested the PR I had a case where $header was not defined because I received an empty response. I would suggest to check whether $header is set by wrapping the call in if (!empty($header)) { ... }

Copy link
Member

Choose a reason for hiding this comment

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

I just realize we will then also need an else { $this->incomingTrackerCookies = array(); }

Copy link
Member

Choose a reason for hiding this comment

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

@MichaelHeerklotz I think here is still a

if (!empty($header)) {
    $this->parseIncomingCookies(explode("\r\n", $header));
} else {
    $this->incomingTrackerCookies = array();
}

missing but we can patch this also after merging.

Copy link
Author

Choose a reason for hiding this comment

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

I have added a $header = ''; , so it should be fine, or am I missing something?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry I did not see that. Stupid me, that's a much better solution! Cheers :)

PiwikTracker.php Outdated
if (strpos(strtolower($header), 'set-cookie:') !== 0) {
continue;
}
$cookies = trim(substr($header, 11));
Copy link
Member

Choose a reason for hiding this comment

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

It's a small thing but I would recommend to use eg strlen('set-cookie:') instead of hardcoded 11 as it is a bit better to read/understand (although it is kind of obvious in this case and not so much needed).

PiwikTracker.php Outdated
/**
* Reads incoming tracking server cookies.
*
* @param $cookies Array with HTTP response headers as values
Copy link
Member

Choose a reason for hiding this comment

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

I think $cookies is supposed to be $headers

@tsteur
Copy link
Member

tsteur commented Nov 8, 2017

Looks good to me. Left a few minor comment especially about $header possibly not defined eg when the tracking server does not respond. We can merge as soon as this change is made. Well done 👍

@MichaelRoosz
Copy link
Author

Thank you for your excellent code review. I have updated the PR accordingly.

@tsteur tsteur merged commit f9a0168 into matomo-org:master Nov 9, 2017
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