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 28, 2025
1 parent a36507d commit 00dfd92
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Unleash/Communication/UnleashApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,21 @@ private static void SetRequestHeaders(HttpRequestMessage requestMessage, Unleash
const string userAgentHeader = "User-Agent";
const string instanceIdHeader = "UNLEASH-INSTANCEID";

const string identifyConnectionHeader = "x-unleash-connection-id";
const string identifyAppNameHeader = "x-unleash-appname";
const string identifySdkHeader = "x-unleash-sdk";

const string supportedSpecVersionHeader = "Unleash-Client-Spec";

requestMessage.Headers.TryAddWithoutValidation(appNameHeader, headers.AppName);
requestMessage.Headers.TryAddWithoutValidation(userAgentHeader, headers.AppName);
requestMessage.Headers.TryAddWithoutValidation(instanceIdHeader, headers.InstanceTag);
requestMessage.Headers.TryAddWithoutValidation(supportedSpecVersionHeader, headers.SupportedSpecVersion);

requestMessage.Headers.TryAddWithoutValidation(identifyConnectionHeader, headers.ConnectionId);
requestMessage.Headers.TryAddWithoutValidation(identifyAppNameHeader, headers.AppName);
requestMessage.Headers.TryAddWithoutValidation(identifySdkHeader, headers.SdkVersion);

SetCustomHeaders(requestMessage, headers.CustomHttpHeaders);
SetCustomHeaders(requestMessage, headers.CustomHttpHeaderProvider?.CustomHeaders);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Unleash/Communication/UnleashApiClientRequestHeaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ internal class UnleashApiClientRequestHeaders
{
public string AppName { get; set; }
public string InstanceTag { get; set; }
public string ConnectionId { get; internal set; }
public string SdkVersion { get; set; }
public Dictionary<string, string> CustomHttpHeaders { get; set; }
public IUnleashCustomHttpHeaderProvider CustomHttpHeaderProvider { get; set; }
public string SupportedSpecVersion { get; internal set; }
Expand Down
3 changes: 3 additions & 0 deletions src/Unleash/Internal/UnleashServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal class UnleashServices : IDisposable
private static readonly ILog Logger = LogProvider.GetLogger(typeof(UnleashServices));
private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
private readonly IUnleashScheduledTaskManager scheduledTaskManager;
private readonly string connectionId = Guid.NewGuid().ToString();

public const string supportedSpecVersion = "5.1.9";

Expand Down Expand Up @@ -84,6 +85,8 @@ public UnleashServices(UnleashSettings settings, EventCallbackConfig eventConfig
{
AppName = settings.AppName,
InstanceTag = settings.InstanceTag,
ConnectionId = connectionId,
SdkVersion = settings.SdkVersion,
CustomHttpHeaders = settings.CustomHttpHeaders,
CustomHttpHeaderProvider = settings.UnleashCustomHttpHeaderProvider,
SupportedSpecVersion = supportedSpecVersion
Expand Down

0 comments on commit 00dfd92

Please sign in to comment.