Skip to content

Commit

Permalink
feat: client identification headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Tymek committed Jan 21, 2025
1 parent db097e2 commit 458a4c3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Client/DefaultRegistrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,24 @@
use Unleash\Client\Enum\CacheKey;
use Unleash\Client\Helper\StringStream;
use Unleash\Client\Helper\Url;
use Unleash\Client\Helper\Uuid;
use Unleash\Client\Strategy\StrategyHandler;
use Unleash\Client\Unleash;

final class DefaultRegistrationService implements RegistrationService
{
private string $connectionId;

public function __construct(
private readonly ClientInterface $httpClient,
private readonly RequestFactoryInterface $requestFactory,
private readonly UnleashConfiguration $configuration,
private ?string $sdkName = null,
private ?string $sdkVersion = null,
) {
$this->sdkName ??= 'unleash-client-php';
$this->sdkName ??= 'unleash-php';
$this->sdkVersion ??= Unleash::SDK_VERSION;
$this->connectionId = Uuid::v4();
}

/**
Expand All @@ -51,9 +55,15 @@ public function register(iterable $strategyHandlers): bool
->createRequest('POST', (string) Url::appendPath($this->configuration->getUrl(), 'client/register'))
->withHeader('Content-Type', 'application/json')
->withBody(new StringStream(json_encode([
// TODO: delete non-standard redundant headers
'appName' => $this->configuration->getAppName(),
'instanceId' => $this->configuration->getInstanceId(),
'sdkVersion' => $this->sdkName . ':' . $this->sdkVersion,
'sdkVersion' => 'unleash-client-php:' . $this->sdkVersion,

'x-unleash-appname' => $this->configuration->getAppName(),
'x-unleash-sdk' => $this->sdkName . '@' . $this->sdkVersion,
'x-unleash-connection-id' => $this->connectionId,

'strategies' => array_map(fn (StrategyHandler $strategyHandler): string => $strategyHandler->getStrategyName(), $strategyHandlers),
'started' => (new DateTimeImmutable())->format('c'),
'interval' => $this->configuration->getMetricsInterval(),
Expand Down

0 comments on commit 458a4c3

Please sign in to comment.