Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added package name & version to HTTP headers #201

Merged
merged 3 commits into from
Jun 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/AzureExtension/Services/DevBox/AuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Net.Http.Headers;
using AzureExtension.Contracts;
using Microsoft.Windows.DevHome.SDK;
using Windows.ApplicationModel;

namespace AzureExtension.Services.DevBox;

Expand All @@ -16,13 +17,34 @@ public class AuthService : IDevBoxAuthService
private readonly HttpClient _httpArmClient;
private readonly HttpClient _httpDataClient;

private bool IsTest()
{
try
{
return Package.Current.Id.Name.Contains("Test");
}
catch
{
return true;
}
}

public AuthService(IHttpClientFactory httpClientFactory, IArmTokenService armTokenService, IDataTokenService dataTokenService)
{
_httpClientFactory = httpClientFactory;
_armTokenService = armTokenService;
_dataTokenService = dataTokenService;
_httpArmClient = _httpClientFactory.CreateClient();
_httpDataClient = _httpClientFactory.CreateClient();

if (!IsTest())
{
var version = Package.Current.Id.Version;
var versionString = version.Build + "." + version.Major + "." + version.Minor + "." + version.Revision;
var agentHeader = new ProductInfoHeaderValue(Package.Current.Id.Name, versionString);
_httpArmClient.DefaultRequestHeaders.UserAgent.Add(agentHeader);
_httpDataClient.DefaultRequestHeaders.UserAgent.Add(agentHeader);
}
}

/// <summary>
Expand Down
Loading