Skip to content

Commit

Permalink
update sdk headers definitons
Browse files Browse the repository at this point in the history
  • Loading branch information
Tymek committed Jan 22, 2025
1 parent 46a32ff commit 68e07e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Client/DefaultRegistrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(
private ?string $sdkVersion = null,
private ?string $connectionId = null,
) {
$this->sdkName ??= 'unleash-client-php';
$this->sdkName ??= Unleash::SDK_NAME;
$this->sdkVersion ??= Unleash::SDK_VERSION;
$this->connectionId = $connectionId ?? Uuid::v4();
}
Expand Down Expand Up @@ -56,7 +56,7 @@ public function register(iterable $strategyHandlers): bool
->withBody(new StringStream(json_encode([
'appName' => $this->configuration->getAppName(),
'instanceId' => $this->configuration->getInstanceId(),
'sdkVersion' => $this->sdkName . ':' . $this->sdkVersion,
'sdkVersion' => $this->sdkName . ':' . $this->sdkVersion,
'strategies' => array_map(fn(StrategyHandler $strategyHandler): string => $strategyHandler->getStrategyName(), $strategyHandlers),
'started' => (new DateTimeImmutable())->format('c'),
'interval' => $this->configuration->getMetricsInterval(),
Expand Down
15 changes: 9 additions & 6 deletions src/Repository/DefaultUnleashRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Unleash\Client\Exception\HttpResponseException;
use Unleash\Client\Exception\InvalidValueException;
use Unleash\Client\Helper\Url;
use Unleash\Client\Helper\Uuid;
use Unleash\Client\Unleash;

/**
Expand Down Expand Up @@ -88,9 +89,9 @@ public function __construct(
private ClientInterface $httpClient,
private RequestFactoryInterface $requestFactory,
private UnleashConfiguration $configuration,
private string $sdkName = null,
private string $sdkVersion = null,
private string $connectionId = null,
private string $sdkName = Unleash::SDK_NAME,
private string $sdkVersion = Unleash::SDK_VERSION,
private string $connectionId = Uuid::v4(),
) {}

/**
Expand Down Expand Up @@ -512,9 +513,6 @@ private function fetchFeatures(): array
} else {
$request = $this->requestFactory
->createRequest('GET', (string) Url::appendPath($this->configuration->getUrl(), 'client/features'))
->withHeader('x-unleash-appname', $this->configuration->getAppName() ?? $this->configuration->getInstanceId())
->withHeader('x-unleash-sdk', $this->sdkName . ':' . $this->sdkVersion)
->withHeader('x-unleash-connection-id', $this->connectionId)
// TODO: remove non-standard headers
->withHeader('UNLEASH-APPNAME', $this->configuration->getAppName())
->withHeader('UNLEASH-INSTANCEID', $this->configuration->getInstanceId())
Expand All @@ -524,6 +522,11 @@ private function fetchFeatures(): array
$request = $request->withHeader($name, $value);
}

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

try {
$response = $this->httpClient->sendRequest($request);
if ($response->getStatusCode() === 200) {
Expand Down

0 comments on commit 68e07e5

Please sign in to comment.