-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from yrmartinez/issue-24-add-sdk-usage-header
Issue 24 add sdk usage header
- Loading branch information
Showing
3 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
KenticoCloud.ContentManagement/Modules/Extensions/HttpRequestHeadersExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Net.Http.Headers; | ||
using System.Reflection; | ||
|
||
namespace KenticoCloud.ContentManagement.Modules.Extensions | ||
{ | ||
internal static class HttpRequestHeadersExtensions | ||
{ | ||
private const string SdkTrackingHeaderName = "X-KC-SDKID"; | ||
|
||
private const string PackageRepositoryHost = "nuget.org"; | ||
|
||
private static readonly Lazy<string> SdkVersion = new Lazy<string>(GetSdkVersion); | ||
private static readonly Lazy<string> SdkPackageId = new Lazy<string>(GetSdkPackageId); | ||
|
||
|
||
internal static void AddSdkTrackingHeader(this HttpRequestHeaders header) | ||
{ | ||
header.Add(SdkTrackingHeaderName, $"{PackageRepositoryHost};{SdkPackageId.Value};{SdkVersion.Value}"); | ||
} | ||
|
||
private static string GetSdkVersion() | ||
{ | ||
var assembly = Assembly.GetExecutingAssembly(); | ||
var fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location); | ||
var sdkVersion = fileVersionInfo.ProductVersion; | ||
|
||
return sdkVersion; | ||
} | ||
|
||
private static string GetSdkPackageId() | ||
{ | ||
var assembly = Assembly.GetExecutingAssembly(); | ||
var sdkPackageId = assembly.GetName().Name; | ||
|
||
return sdkPackageId; | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters