From 223db10cac75c44ff98bc7abe7dcc04a69d6c0ad Mon Sep 17 00:00:00 2001 From: Yaakov Date: Wed, 2 Jan 2019 21:48:54 +1100 Subject: [PATCH 1/2] Add SteamKit version as default user-agent. Resolves #618. --- .../Configuration/SteamConfigurationBuilder.cs | 11 ++++++++++- SteamKit2/Tests/SteamConfigurationFacts.cs | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/SteamKit2/SteamKit2/Steam/SteamClient/Configuration/SteamConfigurationBuilder.cs b/SteamKit2/SteamKit2/Steam/SteamClient/Configuration/SteamConfigurationBuilder.cs index 82b0ef9b2..aa11a9ef3 100644 --- a/SteamKit2/SteamKit2/Steam/SteamClient/Configuration/SteamConfigurationBuilder.cs +++ b/SteamKit2/SteamKit2/Steam/SteamClient/Configuration/SteamConfigurationBuilder.cs @@ -6,6 +6,8 @@ using System; using System.Net.Http; +using System.Net.Http.Headers; +using System.Reflection; using SteamKit2.Discovery; namespace SteamKit2 @@ -107,6 +109,13 @@ public ISteamConfigurationBuilder WithWebAPIKey(string webApiKey) return this; } - static HttpClient DefaultHttpClientFactory() => new HttpClient(); + static HttpClient DefaultHttpClientFactory() + { + var client = new HttpClient(); + + var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(fieldCount: 3); + client.DefaultRequestHeaders.UserAgent.Add( new ProductInfoHeaderValue( "SteamKit", assemblyVersion ) ); + return client; + } } } diff --git a/SteamKit2/Tests/SteamConfigurationFacts.cs b/SteamKit2/Tests/SteamConfigurationFacts.cs index de5377aa4..38bbead69 100644 --- a/SteamKit2/Tests/SteamConfigurationFacts.cs +++ b/SteamKit2/Tests/SteamConfigurationFacts.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Net; using System.Net.Http; @@ -55,6 +56,9 @@ public void DefaultHttpClientFactory() { Assert.NotNull(client); Assert.IsType(client); + + var steamKitAssemblyVersion = typeof( SteamClient ).Assembly.GetName().Version; + Assert.Equal("SteamKit/" + steamKitAssemblyVersion.ToString(fieldCount: 3), client.DefaultRequestHeaders.UserAgent.ToString()); } } From 771c8200d581801ca009b4d0041e960aba2359bb Mon Sep 17 00:00:00 2001 From: Yaakov Date: Thu, 3 Jan 2019 17:23:00 +1100 Subject: [PATCH 2/2] Simplify --- .../SteamClient/Configuration/SteamConfigurationBuilder.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/SteamKit2/SteamKit2/Steam/SteamClient/Configuration/SteamConfigurationBuilder.cs b/SteamKit2/SteamKit2/Steam/SteamClient/Configuration/SteamConfigurationBuilder.cs index aa11a9ef3..cdf502a71 100644 --- a/SteamKit2/SteamKit2/Steam/SteamClient/Configuration/SteamConfigurationBuilder.cs +++ b/SteamKit2/SteamKit2/Steam/SteamClient/Configuration/SteamConfigurationBuilder.cs @@ -7,7 +7,6 @@ using System; using System.Net.Http; using System.Net.Http.Headers; -using System.Reflection; using SteamKit2.Discovery; namespace SteamKit2 @@ -113,8 +112,8 @@ static HttpClient DefaultHttpClientFactory() { var client = new HttpClient(); - var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(fieldCount: 3); - client.DefaultRequestHeaders.UserAgent.Add( new ProductInfoHeaderValue( "SteamKit", assemblyVersion ) ); + var assemblyVersion = typeof(SteamConfiguration).Assembly.GetName().Version.ToString(fieldCount: 3); + client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("SteamKit", assemblyVersion)); return client; } }