mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-22 08:56:42 -06:00
Add 10 second timeout to matomo requests
This commit is contained in:
parent
c03eea789c
commit
316b88cea6
@ -9,6 +9,8 @@ use Shlinkio\Shlink\Core\Exception\RuntimeException;
|
||||
|
||||
class MatomoTrackerBuilder implements MatomoTrackerBuilderInterface
|
||||
{
|
||||
public const MATOMO_DEFAULT_TIMEOUT = 10; // Time in seconds
|
||||
|
||||
public function __construct(private readonly MatomoOptions $options)
|
||||
{
|
||||
}
|
||||
@ -27,12 +29,16 @@ class MatomoTrackerBuilder implements MatomoTrackerBuilderInterface
|
||||
|
||||
// Create a new MatomoTracker on every request, because it infers request info during construction
|
||||
$tracker = new MatomoTracker($siteId, $this->options->baseUrl);
|
||||
// Token required to set the IP and location
|
||||
$tracker->setTokenAuth($this->options->apiToken);
|
||||
// We don't want to bulk send, as every request to Shlink will create a new tracker
|
||||
$tracker->disableBulkTracking();
|
||||
// Ensure params are not sent in the URL, for security reasons
|
||||
$tracker->setRequestMethodNonBulk('POST');
|
||||
$tracker
|
||||
// Token required to set the IP and location
|
||||
->setTokenAuth($this->options->apiToken)
|
||||
// Ensure params are not sent in the URL, for security reasons
|
||||
->setRequestMethodNonBulk('POST')
|
||||
// Set a reasonable timeout
|
||||
->setRequestTimeout(self::MATOMO_DEFAULT_TIMEOUT)
|
||||
->setRequestConnectTimeout(self::MATOMO_DEFAULT_TIMEOUT)
|
||||
// We don't want to bulk send, as every request to Shlink will create a new tracker
|
||||
->disableBulkTracking();
|
||||
|
||||
return $tracker;
|
||||
}
|
||||
|
@ -39,6 +39,8 @@ class MatomoTrackerBuilderTest extends TestCase
|
||||
|
||||
self::assertEquals('api_token', $tracker->token_auth); // @phpstan-ignore-line
|
||||
self::assertEquals(5, $tracker->idSite); // @phpstan-ignore-line
|
||||
self::assertEquals(MatomoTrackerBuilder::MATOMO_DEFAULT_TIMEOUT, $tracker->getRequestTimeout());
|
||||
self::assertEquals(MatomoTrackerBuilder::MATOMO_DEFAULT_TIMEOUT, $tracker->getRequestConnectTimeout());
|
||||
}
|
||||
|
||||
private function builder(?MatomoOptions $options = null): MatomoTrackerBuilder
|
||||
|
Loading…
Reference in New Issue
Block a user