Skip to content

Commit

Permalink
Merge pull request #620 from SteamRE/618-user-agent
Browse files Browse the repository at this point in the history
Add SteamKit version as default user-agent
  • Loading branch information
yaakov-h authored Feb 4, 2019
2 parents 7ee7702 + 771c820 commit 71340e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using SteamKit2.Discovery;

namespace SteamKit2
Expand Down Expand Up @@ -107,6 +108,13 @@ public ISteamConfigurationBuilder WithWebAPIKey(string webApiKey)
return this;
}

static HttpClient DefaultHttpClientFactory() => new HttpClient();
static HttpClient DefaultHttpClientFactory()
{
var client = new HttpClient();

var assemblyVersion = typeof(SteamConfiguration).Assembly.GetName().Version.ToString(fieldCount: 3);
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("SteamKit", assemblyVersion));
return client;
}
}
}
4 changes: 4 additions & 0 deletions SteamKit2/Tests/SteamConfigurationFacts.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
Expand Down Expand Up @@ -55,6 +56,9 @@ public void DefaultHttpClientFactory()
{
Assert.NotNull(client);
Assert.IsType<HttpClient>(client);

var steamKitAssemblyVersion = typeof( SteamClient ).Assembly.GetName().Version;
Assert.Equal("SteamKit/" + steamKitAssemblyVersion.ToString(fieldCount: 3), client.DefaultRequestHeaders.UserAgent.ToString());
}
}

Expand Down

0 comments on commit 71340e2

Please sign in to comment.